Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Member
 
Posts: 70
Default Set Folder path for entire module

I'm trying to set up some code where I choose the general file path directory at the start (via folderpicker or something), set as a 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 to automatically look in that path for Switchfoot.

Any help is appreciated!

Last edited by KeriM : September 27th 12 at 04:11 PM
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 587
Default Set Folder path for entire module

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 :
I'm trying to set up some code where I choose the general file path
directory at the start (via folderpicker or something), set as a
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 to
automatically look in that path for Switchfoot.

Any help is appreciated!




  #3   Report Post  
Member
 
Posts: 70
Default

Quote:
Originally Posted by isabelle View Post
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 :
I'm trying to set up some code where I choose the general file path
directory at the start (via folderpicker or something), set as a
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 to
automatically look in that path for Switchfoot.

Any help is appreciated!



Thanks again Isabelle! Worked perfectly! :)
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 587
Default Set Folder path for entire module

i'm glad to see that it's working! ..feedback is always appreciated!

--
isabelle


Le 2012-10-02 16:30, KeriM a écrit :


Thanks again Isabelle! Worked perfectly! :)


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Remove end folder from path found with ThisWorkbook.Path command ? dim Excel Programming 9 April 23rd 08 06:04 AM
Relative Path to a Folder Heliocracy Excel Discussion (Misc queries) 3 October 3rd 07 04:28 PM
How to List the names of the subfolders present in the folder (path of folder is given in the textbox by user ) divya Excel Programming 3 November 30th 06 11:34 AM
Path of template folder hmm Excel Programming 2 November 17th 06 02:46 AM
Get Folder Path RNM[_2_] Excel Programming 1 August 8th 04 03:19 AM


All times are GMT +1. The time now is 02:17 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"