PDA

View Full Version : Copy data from another file without opening



Yegimor
12-09-2021, 06:17 AM
Good morning,
I have the file "C:\Users\Itaerxga\Desktop\s.xlsx" workbook "data (2)" and I need to copy from "A2: T30000" and I need to paste this "Campione" workbook to A2.
And must run the vba when opening the file.


Thanks and best regards

jolivanes
12-10-2021, 10:23 AM
Assuming that "data(2)" is the worksheet in the workbook on the desktop that you want to copy from
That the sheet you want to paste the copied data into is "Sheet1" in a workbook named "Campione"
This goes in the "ThisWorkbook" module of the Workbook you want to paste into (Campione).





Private Sub Workbook_Open()
With ThisWorkbook.Sheets("Sheet1").Range("A2:T30000") '<----- Change as required
.Formula = "='C:\Users\Itaerxga\Desktop\[s.xlsx]data(2)'!RC" '<----- Change if required
.Value = .Value
End With
End Sub

Yegimor
12-10-2021, 12:36 PM
Good evening,
Sorry maybe I wrote wrong, basically I have an extracted.xls file with the name "Test" and I'm on cell A2 and I have to copy the file C: \ Users \ Itaerxga \ Desktop \ s.xlsx worksheet "data" A2: T30000.

And the file should run upon opening.

Thanks for the help

jolivanes
12-10-2021, 01:46 PM
What is "an extracted.xls" file?

Sub Get_Data()
With ThisWorkbook.Sheets("Sheet1").Range("A2:T30000") '<----- Change as required
.Formula = "='C:\Users\Itaerxga\Desktop\[s.xlsx]data'!RC" '<----- Change if required
.Value = .Value
End With
End Sub
You say you want data imported without opening workbook.

Yegimor
12-10-2021, 06:17 PM
Excuse me
C:\Users\Itaerxga\Desktop\[s.xlsx]data'! RC


RC I did not understand what it means? must copy from A2: C30000 UNTIL THERE ARE THE VALUES.


Thank you

jolivanes
12-10-2021, 06:55 PM
You have a space before RC. That should not be there. Is the sheet you copy from in the workbook on your desktop named "data" without the double quotations?
I tried it and it works like a charm.
Did you copy the code from Post #4 and pasted it in the ThisWorkbook module, saved the workbook and then opened it?
But why do you say "Without opening"?
You won't even notice that a file will be opened.