Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Autorun macro

Status
Not open for further replies.

crystalreps

Programmer
Apr 13, 2003
7
GB
I have a macro running every 2 minutes which is activated in the "Workbook_Open" function. The Macro is stored as a normal personal macro.
However when I have more than 1 workbook open, the macro tries to run in all of the open workbooks creating an error. How do I assign the macro to a specific workbook only?

Your help is much appreciated.
 
You define which workbook the macro should apply to in the workbook_open sub... or am I missing something? What is the purpose of the macro (what does it do)?

// Patrik
 
How do you define the workbook Patrik?
What code do I use?
A macro named "sh3" runs an advanced filter on sheet 3 of a workbook called "check3test".

Thanks for your help

Garry
 
Insert something like this in the beginning of the code

Code:
dim act_wb as string

act_wb = thisworkbook.name

workbooks("name_of_the_target_workbook.xls").activate

This creates a reference to the workbook you're currently working in.

And then insert this before "end sub"

Code:
workbooks(act_wb).activate

This calles the reference and activates the original workbook.

// Patrik
 
(you must replace "name_of_the_target_workbook.xls" with the filename of the target workbook...)

// Patrik
 
Thanks Patrik...this seems to have solved the problem.

Garry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top