excel中使用VBA代码来提取文件夹名称的具体操作步骤
时间:2023-12-07 11:05:25
在网上看到有人用批处理命令提取文件夹名称。其实在excel中使用VBA代码也同样可以提取文件夹名称。
比如需要将电脑E盘“论坛工作资料”文件夹下面的所有文件夹名称提取出来放在excel工作表的A列,可以使用下面的代码。
使用方法是:新建一个excel文档,按ALT+F11,打开VBE编辑器,单击插入——模块,将下面的代码复制到右边的代码编辑区,然后按工具栏中的“运行”按钮即可。
Sub 提取文件夹名称()
Dim fs As Object
n = 1
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.getfolder("E:论坛工作资料")
For Each fd In f.subfolders
Cells(n, 1) = fd.Name
n = n + 1
Next
Set f = Nothing
Set fs = Nothing
End Sub
下面是VBE编辑器中写入的提取文件夹名称相关的一个截图演示:
举一反三,如果需要提取F盘下面文件夹名称,路径更改一下就OK。
标签:VBA代码来提取文件夹名称
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Win10重装系统时提示要输入Microsoft账户怎么解决?
2022-03-31 05:50:21
![](https://img.aspxhome.com/file/2023/26/a219873_0s.png)
Win7系统打开MDB文件的方法介绍
2022-05-06 00:44:25
![](https://img.aspxhome.com/file/2023/2/a291298_0s.jpg)
Word主控文档是什么
2023-12-10 16:01:06
![](https://img.aspxhome.com/file/2023/5/20765_0s.png)
Word2007如何删除首页页码?
2023-12-12 23:15:25
怎么找到Win10 20H2的控制面板?
2023-11-13 18:14:14
![](https://img.aspxhome.com/file/2023/3/49233_0s.jpg)
Word文档怎么快速对齐所有图片
2022-08-10 09:19:41
![](https://img.aspxhome.com/file/2023/1/31191_0s.png)
word文档中如何更改目录的字体颜色
2023-11-30 10:26:25
![](https://img.aspxhome.com/file/2023/7/18577_0s.jpg)
Win8如何设置IE为默认的HTML编辑器
2022-03-01 20:27:30
![](https://img.aspxhome.com/file/2023/28/a250140_0s.jpg)
Win10安装更新后无法还原解决方法?
2022-07-06 21:16:19
![](https://img.aspxhome.com/file/2023/26/a222154_0s.png)
5分钟让你学通Excel中的IF函数
2023-07-08 16:56:50
![](https://img.aspxhome.com/file/2023/6/a157366_0s.png)
百度贴吧怎么用涂鸦回复帖子?
2023-04-18 07:39:57
![](https://img.aspxhome.com/file/2023/8/a339882_0s.jpg)
Win7内外网都能ping通却不能上网怎么办?
2023-12-07 12:04:54
![](https://img.aspxhome.com/file/2023/27/a231744_0s.jpg)
Win10更新显卡驱动时提示“无法连接到NVIDIA”怎么办?
2023-05-21 20:10:43
![](https://img.aspxhome.com/file/2023/26/a225084_0s.jpg)
WPS只打的出字母怎么解决
2023-07-31 21:00:16
![](https://img.aspxhome.com/file/2023/9/a186009_0s.jpg)
WPS 2019首行缩进2个字符
2023-12-05 01:02:43
Win7系统电脑当中的temp文件是如何清理的?
2022-06-12 14:04:53
![](https://img.aspxhome.com/file/2023/4/a307712_0s.jpg)
英伟达511.79显卡驱动发布 支持命运2:女巫女王和iRacing中引入的NVIDIA
2023-06-07 13:22:29
![](https://img.aspxhome.com/file/2023/1/a277485_0s.jpg)
Win10玩不了红警怎么回事?Win10玩不了红警的解决方法
2022-04-13 00:05:30
![](https://img.aspxhome.com/file/2023/1/a281200_0s.png)
excel2003行自动合计的教程
2023-08-21 03:10:27
word 2010 艺术字的插入
2023-01-06 00:53:26
![](https://img.aspxhome.com/file/2023/6/24826_0s.jpg)