Hi all,
I am using this snippet of code (sorry code-->html is not functioning atm) to get a folder name, which is also a project name that the user needs to enter into a cell.
I want to automate this as the names are very long, convoluted and I don't want them to have to rename-copy-paste to get them into the sheet.
Code:
-----------------------------------------
Private Sub cmdGetfolder_Click()
Dim TheChosenPath As String
TheChosenPath = BrowseForFolder("Please select your folder", 17)
If TheChosenPath <> "" Then
txtprojname = TheChosenPath
Else
'do something else or nothing at all...
End If
End Sub
Private Function BrowseForFolder(Title As String, Optional RootFolder As Variant) As String
Dim Shell, Folder
Set Shell = CreateObject("Shell.Application")
Set Folder = Shell.BrowseForFolder(0, Title, 0, RootFolder)
If (Not Folder Is Nothing) Then
BrowseForFolder = Folder.Self.Path
BrowseForFolder = Right(BrowseForFolder, InStrRev(BrowseForFolder, "\") - 1)
Else
End If
End Function
-----------------------------
The problem I am having is at this point:
BrowseForFolder = Right(BrowseForFolder, InStrRev(BrowseForFolder, "\") - 1)
When i have a folder named: Li_Pinal_FC3_4_031907 it is being parsed to inal_FC3_4_031907 for some reason it is dropping off the "Li_P"
BUT if I have a folder named: 11172006_Downtown it is being parsed correctly and the text return is: 11172006_Downtown
What is happening, and is there a better way to get the folder name by selection. The folder has nothing to do with the sheet the form is in, the form is a data entry tool to add many lines of metadata.
Note: The folder names will always have at least one, if not more 'underscore's in the foldername.
I am using this snippet of code (sorry code-->html is not functioning atm) to get a folder name, which is also a project name that the user needs to enter into a cell.
I want to automate this as the names are very long, convoluted and I don't want them to have to rename-copy-paste to get them into the sheet.
Code:
-----------------------------------------
Private Sub cmdGetfolder_Click()
Dim TheChosenPath As String
TheChosenPath = BrowseForFolder("Please select your folder", 17)
If TheChosenPath <> "" Then
txtprojname = TheChosenPath
Else
'do something else or nothing at all...
End If
End Sub
Private Function BrowseForFolder(Title As String, Optional RootFolder As Variant) As String
Dim Shell, Folder
Set Shell = CreateObject("Shell.Application")
Set Folder = Shell.BrowseForFolder(0, Title, 0, RootFolder)
If (Not Folder Is Nothing) Then
BrowseForFolder = Folder.Self.Path
BrowseForFolder = Right(BrowseForFolder, InStrRev(BrowseForFolder, "\") - 1)
Else
End If
End Function
-----------------------------
The problem I am having is at this point:
BrowseForFolder = Right(BrowseForFolder, InStrRev(BrowseForFolder, "\") - 1)
When i have a folder named: Li_Pinal_FC3_4_031907 it is being parsed to inal_FC3_4_031907 for some reason it is dropping off the "Li_P"
BUT if I have a folder named: 11172006_Downtown it is being parsed correctly and the text return is: 11172006_Downtown
What is happening, and is there a better way to get the folder name by selection. The folder has nothing to do with the sheet the form is in, the form is a data entry tool to add many lines of metadata.
Note: The folder names will always have at least one, if not more 'underscore's in the foldername.