我在一个文件夹中有8个excel文件。我想从所有excel文件的sheet1复制C3单元格值。 我使用了以下宏来做那个
Sub Converge_ID()
Dim bookList As Workbook
Dim mergeObj As Object, dirObj As Object, filesObj As Object, everyObj As Object
Application.ScreenUpdating = False
Set mergeObj = CreateObject("Scripting.FileSystemObject")
Dim i
i = 0
Dim TTFiles_Path As String
ThisWorkbook.Worksheets(1).Activate
TTFiles_Path = Range("B1").Value
Set dirObj = mergeObj.GetFolder(TTFiles_Path)
Set filesObj = dirObj.Files
For Each everyObj In filesObj
Set bookList = Workbooks.Open(everyObj)
Coverge_ID = Range("C3")
ThisWorkbook.Worksheets(2).Activate
Range("A1").Offset(i, 0) = Coverge_ID
i = i + 1
bookList.Close
Next
End Sub.
当我执行这个宏时,它按预期工作到第8个文件。它复制C3单元格值并按预期粘贴。关闭第8个文件后,我会弹出这个。
如何避免此错误。导致此错误的原因。
答案 0 :(得分:0)
实际上这个问题是由文件损坏引起的。 它按照其他文件的要求工作。