Set Folder path for entire module

K

KeriM

I'm trying to set up some code where I choose the general file pat
directory at the start (via folderpicker or something), set as
variable, then be able to reference that variable throughout my code
It's a network location, I'm not sure if that changes things.

Here is an example:


Code
-------------------


' Sub Path_Name()
' Dim FolderName As Long
' With Application.FileDialog(msoFileDialogFolderPicker)
' .Show
' On Error Resume Next
' FolderName = .SelectedItems(1)
' Err.Clear
' On Error GoTo 0
'End With
' End Sub


-------------------


Let's say I pick the following path in the folder picker
\\documents\music\09.27.12

I want to set that path to the variable "FolderName"

And then I want to reference that variable in the remainder of my code
so if I want to reference the folder "Switchfoot", located in 09.27.12
in another sub procedure, I just need to call FolderName & "Switchfoot
I don't want to have to pick the folder again, I just want it t
automatically look in that path for Switchfoot.

Any help is appreciated
 
I

isabelle

hi,

you must declare the variable outside of macro

--------------------

Dim FolderName As String

Sub test()
'you must run Path_Name macro before this Test
MsgBox FolderName & "\Switchfoot"
End Sub

Sub Path_Name()
With Application.FileDialog(msoFileDialogFolderPicker)
.Show
On Error Resume Next
FolderName = .SelectedItems(1)
Err.Clear
On Error GoTo 0
End With
End Sub


--------------------

--
isabelle



Le 2012-09-27 11:01, KeriM a écrit :
 
K

KeriM

isabelle;1605958 said:
hi,

you must declare the variable outside of macro

--------------------

Dim FolderName As String

Sub test()
'you must run Path_Name macro before this Test
MsgBox FolderName & "\Switchfoot"
End Sub

Sub Path_Name()
With Application.FileDialog(msoFileDialogFolderPicker)
.Show
On Error Resume Next
FolderName = .SelectedItems(1)
Err.Clear
On Error GoTo 0
End With
End Sub


--------------------

--
isabelle



Le 2012-09-27 11:01, KeriM a écrit :-

Thanks again Isabelle! Worked perfectly! :
 

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

Top