Scope of a public variable

J

Jos Vens

Hi,

I was wondering why Excel sometimes loose my public variables. I use the
variables to have references to my open workbooks and their worksheets.
All my workbooks are open. I suppose that when I open a new workbook en
hides it, I have to rerun my procedure DCL_Sheets? The problem is that most
of the time, everything works fine, but all of a sudden, when I use the
reference eg. shSheet22.[A1]="ABC", I get an error and the reason is because
wbFile1 is not anymore recognized.

Thanks

Jos Vens

eg.

Public wbFile1 as workbook, wbFile2 as workbook
Public shSheet11 as worksheet, shSheet12 as worksheet, shSheet21 as
worksheet, shSheet22 as worksheet

Sub DCL_Sheets

set wbFile1 = workbooks("File1.xls")
set wbFile2 = workbooks("File2.xls")

set shSheet11 = wbFile1.sheets("Sheet01")
set shSheet12 = wbFile1.sheets("Sheet02")
set shSheet21 = wbFile2.sheets("Sheet01")
set shSheet22 = wbFile2.sheets("Sheet02")

End sub
 

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