Check that workbook that contains the module is active

Jaymond Flurrie

Well-known Member
Joined
Sep 22, 2008
Messages
919
Office Version
  1. 365
Platform
  1. Windows
I'm working on my thesis and it makes a workbook to which it saves results to.

Once I have driven the code, I get those results and I go to check those and occasionally forget to activate the main workbook, even if I'm editing code in the main workbook's modules.

The question now is that how could I ensure that how my main workbook is active when I drive code from there? In some C# it would be something like "this.workbook.activate", but how does it go with VBA?

I change the name of my main workbook daily (so that I have some backups). That prevents from hard-coding the name of workbook to the code.
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
You shouldn't need to activate workbooks. If your code creates the other workbook, then store a reference to that in a workbook variable. You can always refer to the workbook containing the code directly with ThisWorkbook as Mike said.
 
Upvote 0
You shouldn't need to activate workbooks. If your code creates the other workbook, then store a reference to that in a workbook variable. You can always refer to the workbook containing the code directly with ThisWorkbook as Mike said.

I mean, the code drives itself thru perfectly, and after that I go to "manipulate" the results (or whatever playing around in the result workbook). Once my program is really finished, I'll make this so that my code is driven by pressing a button in a userform, that is located in that "code-workbook". Now when I drive the code directly from VBE, it's that kind of different, that nothing requires me to first click somewhere in the "code-workbook" and especially since I have two monitors, it's way too easy to forget to activate that "code-workbook".

But yes, you are right, I shouldn't need to activate workbooks once the code is finished. This is for testing purposes only.
 
Upvote 0

Forum statistics

Threads
1,213,546
Messages
6,114,255
Members
448,556
Latest member
peterhess2002

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