我有一个宏,用于从目录中的许多 excel 工作簿中导入数据。它在 Excel 2003 中运行良好,但由于我最近升级到 Excel 2010,宏似乎不起作用。激活后,宏不会出错或产生任何东西。我已经更改了所有信任中心设置和我拥有的其他宏(不导入数据宏)工作得很好。我在编写 VBA 方面不是很熟练,也看不出问题可能出在哪里。似乎excel试图运行宏并跳过它曾经做过的所有事情并完成。任何帮助是极大的赞赏。谢谢
Sub GDCHDUMP()
Dim lCount As Long
Dim wbResults As Workbook
Dim twbk As Workbook
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Application.EnableEvents = False
On Error Resume Next
Set twbk = ThisWorkbook
With Application.FileSearch
.NewSearch
'Change path to suit
.LookIn = "R:\ServCoord\GCM\Data Operations\Quality\GDCHDump"
.filename = "*.xls*"
If .Execute > 0 Then 'Workbooks in folder
For lCount = 1 To .FoundFiles.Count 'Loop through all
'Open Workbook x and Set a Workbook variable to it
Set wbResults = Workbooks.Open(filename:=.FoundFiles(lCount), UpdateLinks:=0)
Set ws = wbResults.Sheets(1)
ws.Range("B2").Copy
twbk.Sheets(1).Cells(lCount, 1).PasteSpecial xlPasteValues
wbResults.Close SaveChanges:=False
'There was a lot more lines like the 2 above that I removed for clarity
Next lCount
End If
End With
On Error GoTo 0
Application.ScreenUpdating = True
Application.DisplayAlerts = True
Application.EnableEvents = True
End Sub