ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Workbook Reference for Macros (https://www.excelbanter.com/excel-programming/276223-workbook-reference-macros.html)

Rich[_13_]

Workbook Reference for Macros
 
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

Anders S

Workbook Reference for Macros
 
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

"Rich" skrev i meddelandet
...
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





All times are GMT +1. The time now is 02:13 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com