询问用户input以在VBA中复印纸张

我想从VBA中的特定工作簿复制工作表到我的活动工作簿,并使用它进行大量计算。 现在的问题是,目标表名称总是不断变化,我总是得到一个错误。

Set targetWorkbook = Application.ActiveWorkbook filter = "Text files (*.xls*),*.xls*" Caption = "Please Select the Target file" Ret = Application.GetOpenFilename(filter, , Caption) If Ret = False Then Exit Sub Application.AskToUpdateLinks = False Set wb = Workbooks.Open(Ret) Application.AskToUpdateLinks = True wb.Worksheets("**This Keeeps on Changing**").Move After:=targetWorkbook.Sheets(targetWorkbook.Sheets.Count) 

我可以select或input名称在MsgBox或类似的东西,所以我没有得到一个错误。 请帮忙。

 Sub ertdfgcvb() Set targetWorkbook = Application.ActiveWorkbook Filter = "Text files (*.xls*),*.xls*" Caption = "Please Select the Target file" Ret = Application.GetOpenFilename(Filter, , Caption) If Ret = False Then Exit Sub Set wb = Workbooks.Open(Ret, False) 'why set it on application level when it's an optional argument? shname = InputBox("What worksheet are you looking for?", "Changing sheet names are for losers") For Each Worksheet In wb If LCase(Worksheet.Name) Like "*" & LCase(shname) & "*" Then 'it might be changing but it probably has a fixed part, right? 'note: you can use wildcards and string conversion rules Worksheet.Move After:=targetWorkbook.Sheets(targetWorkbook.Sheets.Count) 'do whatever it did before End If Next End Sub 
 Set targetWorkbook = Application.ActiveWorkbook Filter = "Text files (*.xls*),*.xls*" Caption = "Please Select the Target file" Ret = Application.GetOpenFilename(Filter, , Caption) If Ret = False Then Exit Sub Set wb = Workbooks.Open(Ret, False) 'why set it on application level when it's an optional argument? For Each Worksheet In wb If LCase(Worksheet.Name) Like "*changing*" Then 'it might be changing but it probably has a fixed part, right? 'note: you can use wildcards and string conversion rules Worksheet.Move After:=targetWorkbook.Sheets(targetWorkbook.Sheets.Count) 'do whatever it did before End If Next