Alias for Workbook in called Macro

HWL

Active Member
Joined
Dec 1, 2009
Messages
462
Okay this one is annoying.

I have a call to another macro but I can't seem to reference a workbook in the second macro.

In the first macro I have:
Set Newbook = Workbooks.Add
ThisWorkbook.Sheets(1).Range("R18") = Newbook.Name


In the second macro I have:
Set Newbook = Workbooks(ThisWorkbook.Sheets(1).Range("R18"))

I even tried
Set Newbook = ActiveWorkbook.FullName

But had an error about not having an object.
grrrrrrrrrrrr This one should be simple.

What am I doing wrong that I can refer to this new workbook in the second macro?
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
Where are you trying to save the Name to, cell R18 of your new workbook, or your oiginal one?
 
Upvote 0
Where are you trying to save the Name to, cell R18 of your new workbook, or your oiginal one?

Thisworkbook is the macro launcher, so I am saving to cell R18 of the original. (Thisworkbook)

But shouldn't I be able to assign an alias anytime I want? such as:

Newbook = ActiveWorkbook.Name
 
Last edited:
Upvote 0
If you capture the workbook name in a variable, you can pass it between different macros (include it as a paramter in your second macro).
 
Upvote 0
If you capture the workbook name in a variable, you can pass it between different macros (include it as a paramter in your second macro).

Explain a bit more please.
In the first macro, it is a variable, called NewBook
How do I pass that to the second macro?
Call macro2(NewBook)

???
 
Upvote 0

Forum statistics

Threads
1,224,524
Messages
6,179,308
Members
452,904
Latest member
CodeMasterX

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