Workbook Reference for Macros

  • Thread starter Thread starter Rich
  • Start date Start date
R

Rich

How can I control the workbook reference when I assign a
macro to a toolbar button?

I want the workbook reference to always be the current
workbook.

TIA,
Rich
 
I'm sure the gurus can explain this in more detail, but basically ThisWorkbook
refers to the workbook the macro is stored in, and ActiveWorkbook refers to
the - yes - active workbook.

Enter the following macro in a code module:

'----
Public Sub WorkbookNames()
MsgBox "This = " & ThisWorkbook.Name & " Active = " & ActiveWorkbook.Name
End Sub
'----

HTH
Anders Silvén
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top