ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Multiple workbooks (https://www.excelbanter.com/excel-programming/361901-multiple-workbooks.html)

Robert[_30_]

Multiple workbooks
 
Hello,

I a particular macro I skip several times between two workbooks. As the
name of the mother sheet differs often I would like to replace the name
that I use in the statement to a fixed code so that I do not have to
change the name in the macro each time that I would like to run it. Can
I set some sort of a parameter?

Thanks a lot for your help!!!

Rgds,
Robert


Ivan Raiminius

Multiple workbooks
 
Hi Robert,

Probably you can work with the workbook as an object. Either it is
thisworkbook, or you have to open (create) it, so you can set an object
variable:

dim wb as workbook
set wb=workbooks.open filename:="somebook"
wb.activate

Regards,
Ivan


Robert[_30_]

Multiple workbooks
 
Hi Ivan,

Thanks for the info.

When I add your statement I get a compile error for 'filename'. As I am
not an expert on VBA I was wondering if you could write the statement
down when I want the current workbook to be set as 'wb'

Thanks again!

Rgds,
Robert


Ivan Raiminius

Multiple workbooks
 
Hi Robert,

if you mean active workbook:

dim wb as workbook
set wb=activeworkbook
wb.save 'for example

if you mean workbook that contains the code, it is much simpler:

thisworkbook.activate 'for example

Regards,
Ivan



All times are GMT +1. The time now is 02:42 PM.

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