我是VBA excel的新手。我正在嘗試將工作簿上的工作表上的數據複製到其他工作簿上的其他工作表中。用戶通過文件對話框選擇他們想要打開的文件。但是,我一直得到運行時錯誤9:下標超出範圍。有人可以請賜教。謝謝。將數據從一個工作簿複製到另一個工作簿表
Sub selectfile()
Dim FileToOpen As String
Dim wb2 As Workbook
Dim wb1 As Workbook
Dim sheet As Worksheet
Application.ScreenUpdating = False
Sheet2.Range("A:Y").ClearContents
FileToOpen = Application.GetOpenFilename _
(Title:="Please choose a Excel File to Open", _
FileFilter:="Excel Files *.xlsx(*.xlsx),")
Sheet1.Range("B30").Value = FileToOpen
Set wb2 = Workbooks.Open(FileToOpen)
Set sheet = wb2.Worksheets(1)
wb2.Activate
sheet.Copy After:=Workbooks("OQC_Check_Tools.xlsm").Sheets("Sheet2")
End Sub
錯誤來設置wb2 = workbooks.worksheets(「Sheet1」)行嗎?或在workboos.open線? –
錯誤是在這條線:集片= wb2.Worksheets(「工作表Sheet1」) –
試片,而不是名稱的指數.....像一套表= wb2.worksheets(1) –