How does a macro access its OWN workbook?

M

Maria

How does a macro access its OWN workbook (the workbook where the macro is defined), even when this is not the active workbook
I want to create a read-only 'reference' workbook that contains a collection of macros and a couple of worksheets with reference data. The various reference worksheets will have fixed names, but I want to avoid using a fixed name for the reference workbook
My users will select some cells in a work-in-progress workbook and then invoke one of the macros (they will have the reference workbook open at the same time). The macros will need to access the currently selected cells as well as the reference data.

Any help appreciate
Maria
 
C

Cesar Zapata

you need to use the Thisworkbook to refer to the workbook where the macro is
located. and Activeworkbook where the macro is working on.


Cesar


Maria said:
How does a macro access its OWN workbook (the workbook where the macro is
defined), even when this is not the active workbook?
I want to create a read-only 'reference' workbook that contains a
collection of macros and a couple of worksheets with reference data. The
various reference worksheets will have fixed names, but I want to avoid
using a fixed name for the reference workbook.
My users will select some cells in a work-in-progress workbook and then
invoke one of the macros (they will have the reference workbook open at the
same time). The macros will need to access the currently selected cells as
well as the reference data.
 
P

Pete McCosh

Maria,

when accessing the book the code is in, use:

ThisWorkbook.Sheets("index"). - and so on -

Pete.
-----Original Message-----
How does a macro access its OWN workbook (the workbook
where the macro is defined), even when this is not the
active workbook?
I want to create a read-only 'reference' workbook that
contains a collection of macros and a couple of worksheets
with reference data. The various reference worksheets will
have fixed names, but I want to avoid using a fixed name
for the reference workbook.
My users will select some cells in a work-in-progress
workbook and then invoke one of the macros (they will have
the reference workbook open at the same time). The macros
will need to access the currently selected cells as well
as the reference data.
 
M

Maria

Thanks Cesar and Pete - much appreciated

I do search google before posting questions, but it's not always easy when you don't yet know the exact word to search for... :eek:)
 

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

Top