我在工作簿之间切换时遇到问题。你能看看代码并说出我正在尝试的问题态度有什么问题吗?或者提出一些其他方法来做到这一点。
Sub copy_spreadsheets()
Dim wb As Workbook, wb_main As Workbook, path As String, sheet_name As String, x As Integer, i As Integer, source_sheet As Worksheet, ws As Worksheet
path = "C:\Users\me\Desktop\folder\"
Set wb_main = ThisWorkbook
For x = 2 To 10
i = 2
sheet_name = ("sheet" & i & ".xlsx")
Set wb = Workbooks.Open(path & sheet_name)
Set sourceSheet = Worksheets("sheet1")
sourceSheet.Activate
sourceSheet.Cells.Select
Selection.Copy
Workbooks("C:\Users\me\Desktop\folder\sheet1.xls").Worksheets("Sheet1").Activate
Set ws = Sheets.Add
i = i + 1
Next x
End Sub
答案 0 :(得分:-1)
有一个Workbook.Activate方法以及Worksheet。尝试在激活该工作簿中的工作表之前激活工作簿。