Global Variables Not Accessible

  • Thread starter Thread starter John Baker
  • Start date Start date
J

John Baker

Hi:

I am trying to define two global variables, thus:

Public wbpath As String
Public timesheet As String

My problem is that this set of commands isn't executing. I set the values in auto_open
macro, and these two commands are right before the auto_open macro, but the value of
wbpath isnt recognized by subsequent macros.

Where should I put them to ensure that they execute at startup of the spreadsheet?

Thanks

John Baker
 
John,

Are you declaring the variables in a standard code module? Do you
have Option Explicit at the top of every module? You should be
doing both these things.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 
The code looks like this:


Public wbpath As String
Public timesheet As String
Sub auto_open()
'
' auto_open Macro
' Macro recorded 11/25/2003 by John H Baker
'
wbpath = ActiveWorkbook.Path

timesheet = ActiveWorkbook.Name
'
Sheets("input").Select
Range("a1").Select


ChDir wbpath

End Sub

This module works fine, but others dont appear to pick up the variables.

Regards

John Baker
 
John,

If you edit the code after the variables are set, their values
will be reset. Perhaps this is the root of your problems.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 
Chip:

Thanks, I think that's it.

In other words I need to close and restart after editing to make things work.

Makes sense.

Regards

John
 
Back
Top