VBA for copying remote data

ronwessel

New Member
Joined
May 12, 2005
Messages
35
Hello,

I have a macro that references a defined-name-range to another file
(e.g. CopyFrom_Range ='[some_file.xls]Sheet1'!$A$2:$B$33)

The macro cycles thru the cells of the defined-range with:
For Each c In Range("CopyFrom_Range").

This works as long as the SOME_FILE.XLS is already open. Do I have to manually check-for/open the linked-file, or is there a better way?

Thanks,

Ron
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Hello,

I have a macro that references a defined-name-range to another file
(e.g. CopyFrom_Range ='[some_file.xls]Sheet1'!$A$2:$B$33)

The macro cycles thru the cells of the defined-range with:
For Each c In Range("CopyFrom_Range").

This works as long as the SOME_FILE.XLS is already open. Do I have to manually check-for/open the linked-file, or is there a better way?

Thanks,

Ron

Ron:

Would this help you?

If Not IsFileOpen("D:\SOME_FILE.xls") Then
Workbooks.Open "D:\SOME_FILE.xls"
Else: Windows("SOME_FILE.xls").Activate
End If
 
Upvote 0
Hi John,

Thanks for your example code:
If Not IsFileOpen("D:\SOME_FILE.xls") Then
Workbooks.Open "D:\SOME_FILE.xls"
Else: Windows("SOME_FILE.xls").Activate
End If

...but it's not really what I'm looking for. I was aware that I could manually perform the actions as you describe, but it's going to be more difficult than that. I have a defined-name called "COPY_FROM" that identifies the data to be copied. It's content changes depending on whether the target-file is already opened:
(e.g. ='C:\where_ever\[some_file.xls]Sheet1'!$A$1:$B$33) <--If the file is closed
(e.g. ='[some_file.xls]Sheet1'!$A$2:$B$33) <--If the file is already open

So, for example, to perform the actions of your code, I must first parse-out the filename for use in the OPEN statements, and then parse out the sheet-name for use with the windows-activate command. Since the contents of the defined-name is different depending on whether the file is open, it starts to get a little complicated. I can certainly do this, but I was simply hoping I could be lazy.

Thanks for your feedback,

Ron
 
Upvote 0

Forum statistics

Threads
1,214,793
Messages
6,121,614
Members
449,039
Latest member
Mbone Mathonsi

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top