Click here to Skip to main content
15,668,126 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need to store variable value till the document closed. For example: Once I open a document, I should run the macro which will get variable value using "filedialog" option and that variable should be used by all other macros.
Sub Test_Macro()

Dim docTitle As Document
    Dim stylepath As String
Dim stylename As FileDialog
MsgBox ("Please choose Reference File")

Set stylename = Application.FileDialog(filedialogtype:=msoFileDialogFilePicker)
If stylename.Show Then
stylepath = stylename.SelectedItems(1)
End If

The stylepath variable should be used by other macros as well. After I opened the document I will set this variable by calling this macro function and later on that variable should be stored throughout the session and can be used by other functions as well.How to do it?
Thanks in advance.
Updated 17-Dec-14 22:31pm
Harsh Athalye 18-Dec-14 4:33am    
Declare your stylepath variable outside any sub() as below:

Public stylepath as String

Sub Test_Macro()

This will make your stylepath variable a global variable and should be available throughout the lifetime of the document.
Vidhya Raju 18-Dec-14 4:42am    
ya,you are right!Thank you.

1 solution

Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900