Dim path_feb As String
Dim path_mar As String
Dim wkbk_feb As Workbook
Dim wkbk_mar As Workbook
path_feb = "D:\Tranzit\2016\feb\data_feb.xlsx"
Set wkbk_feb = Workbooks.Open(path_feb)
path_mar = "D:\Tranzit\2016\mar\data_mar.xlsx"
Set wkbk_mar = Workbooks.Open(path_mar)
Worksheets("monthly").Range("A2:A1000").Value = Windows("wkbk_feb").Worksheet("impuls").Range("A2:A1000").Value
Worksheets("monthly").Range("B2:B1000").Value = Windows("wkbk_mar").Worksheet("impuls").Range("A2:A1000").Value
End Sub
我需要一些帮助才能使用此代码。
问题从这里开始:
Worksheets("monthly").Range("A2:A1000").Value = Windows("wkbk_feb").Worksheet("impuls").Range("A2:A1000").Value
所以,我有3个不同路径的文件:
D:\Tranzit\2016\feb\data_feb.xlsx
D:\Tranzit\2016\\mar\data_mar.xlsx
D:\Tranzit\2016\data_final.xlsm
我想从文件1中复制范围A2:A1000
来自" Sheet" Impuls
来自" Sheet"范围A2:A1000
的档案3 monthly
。
和
从文件2复制范围A2:A1000
来自" Sheet" Impuls
来自" Sheet"范围B2:B1000
的档案3 monthly
。
答案 0 :(得分:1)
您将wkbk_feb
和wkbk_mar
声明为工作簿对象,因此您需要直接引用它们:
wkbk_feb.Worksheets("impuls")....
而不是激活或选择任何内容,您应该始终指定工作簿或工作表。所以它应该看起来像
wkbk_total.Worksheets("monthly")... = wkbk_feb.Worksheets("impuls")....