作为更大宏的一部分,我的代码是:
此代码有效,但现在我想修改它,以便用户可以选择要复制的工作表
这是我的代码:
Dim wb3 As Workbook
Set wb3 = ThisWorkbook
Dim wb_mainFile As Workbook
Dim strMainFile As String
strMainFile = Range("G4").Value
'G4 is the cell that contains the path to the workbook that is to be opened
Set wb_mainFile = Workbooks.Open(strMainFile)
ThisWorkbook.Activate
wb_mainFile.Sheets(1).Copy _
After:=wb3.Sheets(wb3.Sheets.Count)
ActiveSheet.Name = "Sheet3"
wb_mainFile.Close
答案 0 :(得分:1)
据我所知,没有办法选择这样的表格 - 所以这有点破解。
这要求用户在所需的工作表上选择一个单元格:
Sub Foo()
Dim mySheet As Excel.Worksheet
Set mySheet = Application.InputBox("Select a cell on the sheet you want to use:", Type:=8).Parent
MsgBox "Chosen sheet is " & mySheet.Name
End Sub
答案 1 :(得分:1)