View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
jeffP jeffP is offline
external usenet poster
 
Posts: 38
Default scope/ lifetime of variable

Thanks for the help and I'm still confused. I run the MyPaths macro on
Workbook open and I can use other subs "for awhile"
but somewhere , somehow the variable VBACKUP loses it value (blank) and I
have to run the MyPaths macro again to use the variable. I read the help
file on "lifetime of a variable" and I "think" it should keep it's value
until the workbook is closed or it's given a different value.
Am I wrong about that.
Any help , understanding and education would be appreciated.

jeffP

... I used to have a handle on life, but it broke.

"Norman Jones" wrote in message
...
Hi Jeff,

One way:

At the top of Module 1, before any procedures, type

Public vbackup As String

and remove

Dim vbackup As String


from your MYPaths sub.

---
Regards,
Norman



"jeffP" wrote in message
...
HI all,
I'm so confused about this.
I've declared a variable and assigned a value in one module and want to
use
it in another (or a few) but I seem to lose the value once I leave the
standard module that I started from. I've include a code example of what
I'm
trying to do.
Any help is always appreciated.

--
jeff

.. I used to have a handle on life, but it broke.

'in module1
Public Sub MYPaths()
Dim vbackup As String
vbackup = Sheets("mypaths").Range("d2").Value
Debug.Print vbackup
' this works fine and I view the value perfectly in immediate window
end sub

'in module2
Public Sub Test()
debug.print vbackup
'returns nothing in the immediate window
end sub