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.
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.
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)