Macro To Open Additional Workbook

chumley

New Member
Joined
Sep 1, 2005
Messages
36
Hi all,

I have what is hopefully a fairly straight forward question that I am hoping someone can help me out with.

I am developing a macro that is stored in my Personal Macro Workbook, hence it can be run on any workbook with any naming convention. I would like it to do the following:

1) Launch the macro whilst in a workbook, the name of which is random
2) Open C:\Folder\Example.xls
3) Return to the original workbook

It is step 3 that i am having trouble with, as the filename could be something different every time.

Any help would be appreciated.
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Before opening the other workbook assign the active workbook to an object variable like this:

Code:
Dim WB As Workbook
Set WB = ActiveWorkbook

Later you can activate that workbook like this:

Code:
WB.Activate
 
Upvote 0
You could set a workbook variable to your current workbook BEFORE you open a workbook (example.xls). So, that you can show it after you have opened it.

for example,
Code:
Dim WB As Workbook
 
Set WB = ActiveWorkbook
'Open a workbook
WB.Activate 'or show... I dunno
 
Upvote 0

Forum statistics

Threads
1,224,566
Messages
6,179,553
Members
452,928
Latest member
101blockchains

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