Hello to all.
I have a macro that allows me to select a folder and then save that selected location as a variable in a String format.
Once I select the folder, I will need to extract a portion of that folder's name to save as a variable to use in another section of my coding.
The portion I need will always be the first two characters of the folder name and they will always be numerical.
An example would be: C:\Location\Of\The\Folder\I\Have\Selected\09 - Sep
The folder is "09 - Sep", and I need to extract the "09" from that folder name to save as my variable.
Any ideas?
I believe that I will need to use the FileSystemObject, but am not 100% sure on how I should implement it.
I was thinking of something such as this:
However, I can't seem to figure out from here how to isolate the first two characters of the folder selected.
Any pointers?
-Spydey
I have a macro that allows me to select a folder and then save that selected location as a variable in a String format.
Code:
Sub SelectFolder()
Dim SourcePath As String
MsgBox "Please choose the correct folder", vbQuestion, "Folder"
Application.DisplayAlerts = False
With Application.FileDialog(msoFileDialogFolderPicker)
If .Show <> -1 Then MsgBox "No folder selected! Exiting script.": End
SourcePath = .SelectedItems(1)
End With
End Sub
Once I select the folder, I will need to extract a portion of that folder's name to save as a variable to use in another section of my coding.
The portion I need will always be the first two characters of the folder name and they will always be numerical.
An example would be: C:\Location\Of\The\Folder\I\Have\Selected\09 - Sep
The folder is "09 - Sep", and I need to extract the "09" from that folder name to save as my variable.
Any ideas?
I believe that I will need to use the FileSystemObject, but am not 100% sure on how I should implement it.
I was thinking of something such as this:
Code:
Sub SelectFolder()
Dim fso as New FileSystemObject
Dim SourcePath As String
Dim foldername As String
MsgBox "Please choose a folder", vbQuestion, "Folder"
Application.DisplayAlerts = False
With Application.FileDialog(msoFileDialogFolderPicker)
If .Show <> -1 Then MsgBox "No folder selected! Exiting script.": End
SourcePath = .SelectedItems(1)
foldername = fso.GetFolder(.SelectedItems(1))
End With
End Sub
However, I can't seem to figure out from here how to isolate the first two characters of the folder selected.
Any pointers?
-Spydey