Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Public variable lost...

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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,236
Default Public variable lost...

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.

--
Rob van Gelder - http://www.vangelder.co.nz/


wrote in message
oups.com...
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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Public variable lost...

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

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,236
Default Public variable lost...

Could you please post the code for Test.xls!Test


--
Rob van Gelder - http://www.vangelder.co.nz/


wrote in message
oups.com...
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



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Public variable Jack New Users to Excel 4 March 18th 06 09:35 PM
Public Variable not maintaining value. Mark Excel Programming 1 September 7th 05 07:16 PM
Public Variable in ThisWorkbook DRKML Excel Programming 2 April 11th 05 07:16 PM
Public Variable Jason Excel Programming 4 April 12th 04 07:06 PM
public variable marwan hefnawy Excel Programming 1 September 5th 03 08:54 AM


All times are GMT +1. The time now is 04:00 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"