遍历一个文件夹内的所有EXCEL工作簿,找出同名的例如每个工作簿中Sheet2这张工作表全部打印出来的VBA。

下面这段函数运行的时候出现 438错误和 1004错误,请帮忙看下,谢谢。
Sub prt()
Dim ws As Workbook, path$, d$
Application.ScreenUpdating = False
path = ThisWorkbook.path & "\"
d = Dir(path & "*.xls")
Do While d <> "'"
If d <> ThisWorkbook.Name Then
Set ws = Workbooks.Open(path & d)
ws.Sheets("sheet2").PrintOut
ws.Close False
End If
d = Dir
Loop
Application.ScreenUpdating = True
End Sub

第1个回答  2015-09-14
Sub prt()
Dim ws As Workbook, path$, d$
Application.ScreenUpdating = False
path = ThisWorkbook.path & "\"
d = Dir(path & "*.xls")
Do While d <> "'"
If d <> ThisWorkbook.Name Then
Set ws = Workbooks.Open(path & d)
ws.Worksheets("sheet2").select
Activesheet.PrintOut
ws.Close False
End If
d = Dir
Loop
Application.ScreenUpdating = True
End Sub本回答被网友采纳
第2个回答  2015-09-14
除了Do While d <> "'"多一个单引号程序没什么问题
相似回答