vba - 从文件路径中提取文件夹名称
问题描述
目前,我在 excel vba 上使用它来生成一个文本框供我输入文件路径:
Dim FilePath As String
Cells.Select
Selection.ClearContents
FilePath = InputBox("Hi Production Controller! Where is your file path?")
我需要从此文件路径中提取 2020 年 2 月 14 日:
O:\Folder1\Folder2\Folder3\2020\02 二月\2020 年 2 月 14 日
并将其插入单元格 C1。我能得到一些帮助吗?我是vba的初学者。
解决方案
我需要从此文件路径中提取 2020 年 2 月 14 日:
O:\Folder1\Folder2\Folder3\2020\02 二月\2020 年 2 月 14 日
尝试这个
Option Explicit
Sub Sample()
Debug.Print GetFileFolderFromPath("O:\Folder1\Folder2\Folder3\2020\02 Feb\14 Feb 2020")
End Sub
Public Function GetFileFolderFromPath(ByVal strPath As String) As String
If Right$(strPath, 1) <> "\" And Len(strPath) > 0 Then _
GetFileFolderFromPath = GetFileFolderFromPath(Left$(strPath, Len(strPath) - 1)) + _
Right$(strPath, 1)
End Function
推荐阅读
- azure-ad-b2c - 如何在 Azure B2C 错误页面 api.error 中自定义错误文本
- python - 为什么“StratifiedShuffleSplit”对数据集的每个拆分都给出相同的结果?
- javascript - Firebase JavaScript JQuery 图像链接显示问题
- azure - azure 为物联网中心创建服务主体
- python - 如何解决神经网络中的权重问题
- perl - Perl 中的格式输出
- php - 带有 nginx 和 worker_processes 的 Docker 环境
- sql - Hive - 爆炸和汇总计数?
- webdriver-io - WebdriverIO 从表列中获取所有值
- python - 到熊猫数据框的嵌套字典列表(类型对象'DataFrame'没有属性'from_items')