我有一个VBA脚本,可以为大约500个excel文件添加工作表.我在运行VBA脚本和添加简单工作表时没有遇到任何问题,但是当我尝试在其中添加带有VBA脚本的工作表以及图形和按钮时,它会工作一段时间而不是冻结.
这是代码.我知道它没有错误处理 - 任何建议如何解决这个问题或者是什么导致excel冻结?
Sub FindOpenFiles()
Const ForReading = 1
Set oFSO = New FileSystemObject
Dim txtStream As TextStream
Dim FSO As Scripting.FileSystemObject, folder As Scripting.folder, file As Scripting.file, wb As Workbook, sh As Worksheet
Dim directory As String
'The path for the equipement list. - add the desired path for all equipement or desired value stream only.
Set txtStream = oFSO.OpenTextFile("O:\SiteServices\Maintenance\Maintenance Support Folder\Maintenance Department Information\HTML for Knowledgebase\Excel for Knowledgebase\Equipement paths-all.txt", ForReading)
Do Until txtStream.AtEndOfStream
strNextLine = txtStream.ReadLine
If strNextLine …Run Code Online (Sandbox Code Playgroud) 我有一个示例 MS Excel 表:
我正在尝试编写一个允许我比较行的 VBA 宏,比较是使用多个单元格(A2:E2)完成的,其余单元格(F2:I2)将合并其值而不进行比较。我希望能够比较一行 - 单元格(A2:E2)到单元格(A3:E3),然后单元格(A2:E2)到单元格(A4:E4)......完成比较后它会合并重复项 - 这样单元格(Fx:Ix)也会合并。
最终效果如下:
到目前为止,我已经想出了这段代码,但是运行它会使 Excel 崩溃。任何形式的建议将不胜感激。
提前致谢
Sub MergeDuplicateRows()
Dim i As Long
Dim j As Long
Dim RowCount As Long
Dim sameRows As Boolean
sameRows = True
RowCount = Rows.Count
Application.DisplayAlerts = False
Application.ScreenUpdating = False
For i = 1 To Range("B" & RowCount).End(xlUp).Row
For j = 1 To 5
If StrComp(Cells(i, j), Cells(i + 1, j), vbTextCompare) Then
sameRows = False
End If
Next j
If sameRows Then
Range(Cells(i, …Run Code Online (Sandbox Code Playgroud)