excel - 从 Excel VBA 中此文件夹路径内的文件中获取文件夹路径
问题描述
我很惊讶通过在互联网上搜索简单的解决方案来找到它并不是那么容易,因为它可以快速集成到我的代码中。在许多情况下,答案与其他事物相结合。我将提出我的解决方案,并等待解决此问题的其他答案。
解决方案
由于这个函数时常出现,我需要在我的项目中决定为它创建一个单独的函数。它的代码如下:
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 对象是不值得的。
推荐阅读
- c# - 按钮加载更多数据到DatagridView,超过20000个注册C#
- vue.js - Vue.js doesn't render loop properly when chaning value through the v-model
- c - 你能解释一下为什么p[-1]是可能的吗?
- ios - 在运行时列出设备上的所有临时配置文件并获取它们的到期日期
- hbase - 实时流数据分析
- tcp - 无法理解标头中的 uTorrent 传输协议“扩展”选项
- visual-studio-code - 使用 CTRL + 单击在 Java 项目中导航的 Visual Studio 代码扩展
- domain-driven-design - 使用事件溯源,如何使代表报告/索赔/记录的事件无效和更正?
- javascript - Angular - 获取元素的点击绑定表达式
- javascript - 我可以使用原型模式而不是闭包模式来创建解析为对象的承诺吗?