我有以下代码将工作簿中的对象列出到另一个工作簿中;
For Each ws In mainworkBook.Sheets
For Each includedObjects In ws.Shapes
outputBook.Sheets("Sheet1").Range("A" & i) = ws.Name
outputBook.Sheets("Sheet1").Range("B" & i) = TypeName(includedObjects)
outputBook.Sheets("Sheet1").Range("C" & i) = includedObjects.Name
i = i + 1
Next
Next
但是,这需要 5 分钟才能运行并列出大约 2500 个对象。但是这个输出到 CSV 文件的代码只需要几秒钟就可以得到相同的结果。
objFile.writeline "Sheet, Object Type, Object name"
For Each ws In ActiveWorkbook.Sheets
For Each includedObjects In ws.Shapes
objFile.writeline ws.Name & "," & TypeName(includedObjects) & "," & includedObjects.Name
Next
Next
如何改进第一个代码以使其运行得更快?
这应该更快一些:
(如果9999不够用,就加大)
笔记: