简体   繁体   中英

How to copy data from one already opened excel file (Workbook1,Sheet1,cell A11) to another already opened excel file(workbook2,sheet1,A11)

I have 2 different opened excel files i want to copy data from first to secound file using macro in the first excel file?

I use this code but it does work when the two Workbooks are opened in 1 excel file when they are opened in two different excel files it says "Run time error 9" or something like this

Sub Macro2()

Macro2 Macro

Range("D5:L5").Select
Selection.Copy
Windows("New_SET_Data.xlsx").Activate
Range("B7").Select
Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
    False, Transpose:=True
Windows("Original_SET_Data.xls").Activate

End Sub

how to change the code so i will get data from workbook1 in excelfile "A" to workbook2 in excel file "B"

you could use GetInfoFromClosedFile() i guess, but i never tested.

I remember using:

dim txt = "'C:\[test.xls]Page 1'!R1C1"

this should work in theory...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM