Public variable lost...

  • Thread starter Thread starter a.ohlund
  • Start date Start date
A

a.ohlund

Hi,
I wonder if anyone has encountered the same problem? ( probably huh...
: ) )
From a sub in a workbook saved in Excel2003, I open a second (template)
workbook saved in Excel2k. After opening the workbook I call a sub by
Application.Run to set a global variable in the opened workbook but
after exiting the sub in the original workbook, the global in the
opened workbook is reset (or lost). See example code below:

Public Sub CallTest()
Call Workbooks.Open(ThisWorkbook.Path & "\Test.xls")
Call Application.Run("Test.xls!Test", blnTest)
End Sub

Is it a known bug? Does anyone know how to work around the problem
without having to save the workbooks in the same Excel version. If the
workbooks are saved in the same version of Excel, the problem will not
occur! I have already tried that...

Thak you!
//Anders SWE
 
I'm guessing that you've created blnTest in ThisWorkbook instead of the
opened Workbook (whether you knew it or not).

At the top of your code (in both Workbooks), place the following line:
Option Explicit

That enforces variables be declared before use. Might highlight your
problem.
 
Hi Rob,
Both the workbooks are Option Explicit and blnTest is actually just a
typo in the code, would just have said "True" instead, but thanks
anyway!

//Anders
 

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

Back
Top