Application: Excel
Left(ThisWorkbook.Path, InStrRev(ThisWorkbook.Path, "\") - 1)
I need to go back at least 2 Folders from the Workbook Path.
I cannot use Paths like "C:/Folder1", because the Application will be moved multiple times.
VBA Open File Dialog Box helps to browse a file and open Excel Workbook. Users can choose file by clicking on the button to open an Excel File with specific filter, title.
Like this:
Function getParentFolder2(ByVal strFolder0)
Dim strFolder
strFolder = Left(strFolder0, InStrRev(strFolder0, "\") - 1)
getParentFolder2 = Left(strFolder, InStrRev(strFolder, "\") - 1)
End Function
Dim strFolder
strFolder = getParentFolder2(ThisWorkbook.Path)
We here cut twice \subdir pattern...
The FileSystemObject
provides the method GetParentFolderName(path)
.
See How do I use FileSystemObject in VBA?
Dim fso As New FileSystemObject
Dim strParent As String
strParent = fso.GetParentFolderName(Me.Range("A1").value)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With