将特定的工作表从多个工作簿复制到主工作簿

时间:2018-11-23 09:35:07

标签: excel vba excel-vba

我正在尝试从装满工作簿的文件夹中复制特定的工作表(称为“编辑”)(190)。我有以下代码可以做到这一点:

Option Explicit
Sub CombineSheets()
Dim sPath As String
Dim sFname As String
Dim wBk As Workbook
Dim wSht As Variant

Application.EnableEvents = False
Application.ScreenUpdating = False
sPath = InputBox("M:\Employee Information\Peter Young\Msc Project\1 - 181028 - Office First Floor\MacroCopy")
ChDir sPath
sFname = InputBox("*")
sFname = Dir(sPath & "\" & sFname & ".xl*", vbNormal)
wSht = InputBox("Edit")
Do Until sFname = ""
    Set wBk = Workbooks.Open(sFname)
    Windows(sFname).Activate
    Sheets(wSht).Copy Before:=ThisWorkbook.Sheets(1)
    wBk.Close False
    sFname = Dir()
Loop
ActiveWorkbook.Save
Application.EnableEvents = True
Application.ScreenUpdating = True
End Sub

运行宏时,出现对​​话框,要求命名工作表以从所有匹配的工作簿中复制。我输入“编辑”,并收到消息“运行时错误'76':找不到路径”,谁能告诉我要更改此代码需要进行什么操作??

0 个答案:

没有答案