Excel获取指定路径的文件名 vba代码
时间:2023-02-04 05:05:55
在Excel VBA中,如果需要Excel获取指定路径的文件名以方便用户的操作体验,可通过VBAExcel获取指定路径的文件名。Excel2003可通过VBA宏Excel获取指定路径的文件名。
Excel获取指定路径的文件名的方法:
首先按“Alt+F11”组合键,Excel2003打开代码编辑器,单击“插入”菜单-“模块”,双击插入的模块,在右侧的代码窗口中输入:
Sub Excel_Partner()
Dim myFilename As String, myPath As String
ChDir Application.DefaultFilePath ‘改变默认路径
myPath = "C:\" ‘指定的任意路径
SendKeys myPath & "{TAB}" ‘将指定的任意路径发送到“打开”对话框
myFilename = Application.GetOpenFilename
Range("A1") = myFilename
End Sub
按F5运行键运行程序,Excel调用“打开”对话框,自动打开指定的路径。双击指定的文件,Excel获取指定路径的文件名。
相关说明: 当输入法处于中文输入法状态时,将不能打开指定的路径。
标签:指定,文件名,获取,路径,Excel函数
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Win7阻止窗口颜色修改的技巧
2022-12-11 00:05:11
![](https://img.aspxhome.com/file/2023/27/a232966_0s.jpg)
Win10如何关闭“来自microsoft download/upload host”进程?
2023-03-18 22:20:34
![](https://img.aspxhome.com/file/2023/26/a225340_0s.jpg)
WPS表格办公—LOWER函数的用法
2022-08-12 22:17:47
Win7笔记本连接隐藏WiFi方法分享
2022-10-09 10:11:36
![](https://img.aspxhome.com/file/2023/1/a281786_0s.png)
Powerpoint播放时能偷看备注
2023-02-09 11:16:18
Excel用名称框快速定义区域名称
2022-10-02 11:01:37
![](https://img.aspxhome.com/file/2023/3/a156713_0s.jpg)
WPS如何批量删除空格操作方法分享
2022-02-04 07:56:54
![](https://img.aspxhome.com/file/2023/1/a182511_0s.png)
excel公式数值化的图文教程详解
2022-04-26 07:04:29
api-ms-win-core-path-l1-1-0.dll 是什么?api-ms-win-core-path-l1-1-0.dll 丢失
2023-04-12 12:11:32
![](https://img.aspxhome.com/file/2023/1/a272506_0s.png)
wps表格教程怎么求乘法
2023-02-27 22:45:30
Win10系统怎么深度清理C盘?Win10系统深度清理C盘操作方法
2023-03-14 17:56:26
![](https://img.aspxhome.com/file/2023/1/52861_0s.png)
win7旗舰版把桌面路径移至D盘的方法
2023-05-24 01:27:34
![](https://img.aspxhome.com/file/2023/29/a251783_0s.jpg)
win10系统可以自动换壁纸吗?win10系统自动更换壁纸的设置方法
2022-11-12 20:14:28
![](https://img.aspxhome.com/file/2023/28/a246995_0s.jpg)
WPS文字技巧:有公式的行距也能调
2022-08-25 19:42:10
![](https://img.aspxhome.com/file/2023/3/a164373_0s.jpg)
PD虚拟机教程:如何在PD虚拟机中设置新建现有虚拟机时需密码?
2022-12-25 15:27:28
![](https://img.aspxhome.com/file/2023/5/a202405_0s.jpeg)
Win8系统下格式化U盘提示Windows无法完成格式化
2023-07-10 03:39:51
![](https://img.aspxhome.com/file/2023/2/a285239_0s.jpg)
Win10电脑所有字体有阴影怎么办?
2023-11-25 06:25:40
![](https://img.aspxhome.com/file/2023/4/50894_0s.png)
显卡天梯图2022年06月 2022最新显卡排行榜天梯图
2023-10-03 05:49:04
![](https://img.aspxhome.com/file/2023/1/a273184_0s.png)
Roaming文件夹可以删除吗?
2023-06-19 03:26:15
![](https://img.aspxhome.com/file/2023/6/a321109_0s.png)
欧朋浏览器怎么收藏网页 欧朋浏览器收藏网页的教程
2023-04-26 13:53:49
![](https://img.aspxhome.com/file/2023/8/a338106_0s.jpg)