VBA to return to a workbook whose name has been changed

salam3623

New Member
Joined
Jul 8, 2013
Messages
4
Hi,
Is there a way to write VBA in excel 2010 to cycle back to an open workbook (A) whose name has been changed? When this workbook (A), whose name changes each time it's released to user, runs through and a series of Macros, it leads them down a path to a newly created workbook(B). I need the macros to continue on and cycle back to the orginal workbook(A), but it's reference back to workbook (A) must vary based on workbook (A)'s name. All VBA is housed within Workbook (A) and runs off this workbook- the originator has to change name, though, each time it's released.
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Any reference to "ThisWorkbook", as in "ThisWorkbook.Sheet1.Range("A1") = 5", will always refer to the workbook in which the macro code is running, so you could just preface all your macro code with that.

Or, you can create a workbook object and link it to book A:

Code:
Dim wrkbk as New Workbook

Set wrkbk = ActiveWorkbook 'assuming A is active

'now run code that creates and does stuff in B

'now it's time to return to A:
wrkbk.Sheet1.Range("A1") = "hello"

'clean up
Set wrkbk = Nothing
 
Upvote 0

Forum statistics

Threads
1,215,377
Messages
6,124,598
Members
449,174
Latest member
chandan4057

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