ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Global Variables (https://www.excelbanter.com/excel-programming/416659-global-variables.html)

MM User

Global Variables
 
Hi,

Is it possible to add a sub that can be used to set all variables:

Private Sub Workbook_Open()
Run setvalues
End Sub

Public Sub myvalues()
ProjectTitle = "my Project"
End Sub

Thanks!

Per Jessen

Global Variables
 
Hi

Yes, it's possible...

The secret is to declare the variables outside your macro (at the top of the
module).

Try this:

Private Sub Workbook_Open()
Call myvalues
Call output
End Sub

Dim ProjectTitle As String
Public Sub myvalues()
ProjectTitle = "my Project"
End Sub

Sub output()
msg = MsgBox("ProjectTitle = " & ProjectTitle)
End Sub

For more information about declaring variables, look at this:

http://www.cpearson.com/excel/variables.htm

Best regards,
Per

"MM User" skrev i meddelelsen
...
Hi,

Is it possible to add a sub that can be used to set all variables:

Private Sub Workbook_Open()
Run setvalues
End Sub

Public Sub myvalues()
ProjectTitle = "my Project"
End Sub

Thanks!



MM User

Global Variables
 
Thanks Per - that's great!

"Per Jessen" wrote in message
...
Hi

Yes, it's possible...

The secret is to declare the variables outside your macro (at the top of
the module).

Try this:

Private Sub Workbook_Open()
Call myvalues
Call output
End Sub

Dim ProjectTitle As String
Public Sub myvalues()
ProjectTitle = "my Project"
End Sub

Sub output()
msg = MsgBox("ProjectTitle = " & ProjectTitle)
End Sub

For more information about declaring variables, look at this:

http://www.cpearson.com/excel/variables.htm

Best regards,
Per

"MM User" skrev i meddelelsen
...
Hi,

Is it possible to add a sub that can be used to set all variables:

Private Sub Workbook_Open()
Run setvalues
End Sub

Public Sub myvalues()
ProjectTitle = "my Project"
End Sub

Thanks!




All times are GMT +1. The time now is 02:50 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com