问题描述
令我惊讶的是,为此目的,通过在互联网简单解决方案中进行搜索并不是很容易找到,该解决方案可以快速集成到我的代码中.在许多情况下,答案与其他事物结合在一起.我将提出解决方案,并在解决该问题的过程中等待其他答案.
I was surprised that it wasn't so easy to find through searching in internet simple solution for this purpose which can be quickly integrated into my code. In many cases, answers are integrated with other things. I will propose my solution and will wait for other answers where this problem is solved.
推荐答案
由于该函数会不时出现,因此在我的项目中,我需要为其创建一个单独的函数.它的代码如下:
As this function from time to time, I need in my projects I decided to create a separate function for it. The code of it is below:
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对象.
In some solutions for this purpose, I used FSO, but it takes resources, and I think it isn't worthy to create FSO object if you need it only for this simple function.
这篇关于从Excel VBA中此文件夹路径内的文件获取文件夹路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!