[英]Get folder path from file inside this folder path in Excel VBA
我很惊讶通过在互联网上搜索简单的解决方案来找到它并不是那么容易,它可以快速集成到我的代码中。 在许多情况下,答案与其他事物相结合。 我将提出我的解决方案,并等待解决此问题的其他答案。
由于这个 function 时不时地,我需要在我的项目中我决定为它创建一个单独的 function。 它的代码如下:
Function getFolderPathFromFilePath(filePath As String) As String
Dim lastPathSeparatorPosition As Long
lastPathSeparatorPosition = InStrRev(filePath, Application.PathSeparator)
getFolderPathFromFilePath = Left(filePath, lastPathSeparatorPosition - 1)
End Function
在为此目的的一些解决方案中,我使用了 FSO,但它需要资源,而且我认为如果您只需要它用于这个简单的 function,那么创建 FSO object 是不值得的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.