ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   how can i get a macro in personal.xls to know my current workbook? (https://www.excelbanter.com/excel-programming/369303-how-can-i-get-macro-personal-xls-know-my-current-workbook.html)

[email protected]

how can i get a macro in personal.xls to know my current workbook?
 
Set ws1 = ThisWorkbook.Sheets(1)

Instead of ThisWorkbook, how can I get a macro I have stored in
personal.xls to use the currently active workbook? It is currently
referring only to personal.xls, which needless to say is hidden and
unused. I cannot hard-code a workbook name because every day there is
a new set of workbooks generated from a database, and the names are
always different/dynamic. I need to be able to just open a newly
generated workbook, run my macro, and exit excel as soon as the magic
stops.

Thanks a ton.


ImpulseBlue

how can i get a macro in personal.xls to know my current workbook?
 
ActiveWorkbook.Sheets(1)

wrote:
Set ws1 = ThisWorkbook.Sheets(1)

Instead of ThisWorkbook, how can I get a macro I have stored in
personal.xls to use the currently active workbook? It is currently
referring only to personal.xls, which needless to say is hidden and
unused. I cannot hard-code a workbook name because every day there is
a new set of workbooks generated from a database, and the names are
always different/dynamic. I need to be able to just open a newly
generated workbook, run my macro, and exit excel as soon as the magic
stops.

Thanks a ton.



[email protected]

how can i get a macro in personal.xls to know my current workbook?
 
Awesome, thanks!

I'm an excel noob, but I don't use it enough to need to learn VBA :)

ImpulseBlue wrote:
ActiveWorkbook.Sheets(1)

wrote:
Set ws1 = ThisWorkbook.Sheets(1)

Instead of ThisWorkbook, how can I get a macro I have stored in
personal.xls to use the currently active workbook? It is currently
referring only to personal.xls, which needless to say is hidden and
unused. I cannot hard-code a workbook name because every day there is
a new set of workbooks generated from a database, and the names are
always different/dynamic. I need to be able to just open a newly
generated workbook, run my macro, and exit excel as soon as the magic
stops.

Thanks a ton.




All times are GMT +1. The time now is 07:37 AM.

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