Global Variables

  • Thread starter Thread starter MM User
  • Start date Start date
M

MM User

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!
 
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
 
Thanks Per - that's great!

Per Jessen said:
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
 

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