我已经获得修改某些vba脚本的作业,并且我不确定如何在给定完整路径字符串的情况下获取父文件夹名称。
这是我到目前为止所拥有的:
'=== Required output should be "zzz"
Dim FullFolderName As String
Dim FolderName As String
Dim FullPath As String
FullPath = "x:\xxx\yyy\zzz\somefile.txt"
Dim folderobject
Set folderobject = CreateObject("Scripting.FileSystemObject")
FullFolderName = folderobject.GetParentFolderName(ThisDrawing.FullName)
'FullFolderName ends up with "x:\xxx\yyy\zzz"
'Everything above works. Below does not. I want FolderName to = "zzz"
FolderName = String.Remove(FullFolderName.LastIndexOf("\"))
到目前为止,它似乎比使用.NET更复杂。任何帮助表示赞赏。
答案 0 :(得分:1)
你可以使用instrrev
FolderName = Left(FullFolderName, InStrRev(FullFolderName, "\")-1)