Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从Excel VBA中此文件夹路径内的文件获取文件夹路径_Excel_Vba_Path_Filepath - Fatal编程技术网

从Excel VBA中此文件夹路径内的文件获取文件夹路径

从Excel VBA中此文件夹路径内的文件获取文件夹路径,excel,vba,path,filepath,Excel,Vba,Path,Filepath,我感到惊讶的是,通过在internet上搜索这个可以快速集成到我的代码中的简单解决方案并不是那么容易找到。在许多情况下,答案与其他事物相结合。我将提出我的解决方案,并等待解决此问题的其他答案。由于此功能不时出现,我需要在我的项目中为其创建一个单独的功能。其代码如下: Function getFolderPathFromFilePath(filePath As String) As String Dim lastPathSeparatorPosition As Long las

我感到惊讶的是,通过在internet上搜索这个可以快速集成到我的代码中的简单解决方案并不是那么容易找到。在许多情况下,答案与其他事物相结合。我将提出我的解决方案,并等待解决此问题的其他答案。

由于此功能不时出现,我需要在我的项目中为其创建一个单独的功能。其代码如下:

Function getFolderPathFromFilePath(filePath As String) As String

    Dim lastPathSeparatorPosition As Long

    lastPathSeparatorPosition = InStrRev(filePath, Application.PathSeparator)

    getFolderPathFromFilePath = Left(filePath, lastPathSeparatorPosition - 1)

End Function
在一些用于此目的的解决方案中,我使用了FSO,但它需要资源,并且我认为如果您仅为这个简单的函数需要它,那么创建FSO对象是不值得的