VBA Calling the Wrong Workbook

Michael515

Board Regular
Joined
Jul 10, 2014
Messages
136
Hi Y'all,

At my job we work with multiple workbooks that are created from pulling data from a database. Every one of these workbooks have a refresh button that refreshes the workbook (all straight forward enough so far haha). I have made created a workbook (lets call it workbook A) that refreshes itself at certain times and saves itself to a certain shared drive. However, if I'm in any other workbook that has the same refresh button, lets call this workbook B, at the designated time, the call function for workbook A, refreshes workbook B instead of workbook A, and saves workbook B to the shared folder. What I ideally want to happen is to open workbook A at the beginning of the morning, have it refresh itself at 4 designated times during the day, and then close itself at the end of the day, meanwhile I'd be working on workbooks B, C, D etc. throughout the day. I originally though I had the VBA written right, but in today's demo run, when Workbook B was open during the designated time to refresh and save workbook A, workbook B refreshed and saved and not workbook A. Is there any way to have this refresh button (which is common in all the workbooks we work with), only refresh workbook A and NOT the active workbook?

I hope I explained the problem well enough. If you have any questions let me know. Thanks ahead of time for all your help!
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.

CalcSux78

Well-known Member
Joined
Oct 15, 2013
Messages
1,120
Hard to tell what's wrong when we can't look under the hood.... Look into how your refresh command is called. Did you declare as:
Code:
ThisWorkbook.Connections("connection1).Refresh

At a minimum, declare which workbook the connections belong to that you are refreshing.
 
Upvote 0

Forum statistics

Threads
1,195,644
Messages
6,010,893
Members
441,571
Latest member
stolenweasel

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
Top