excel - FSO.重命名子文件夹(循环)
问题描述
我想遍历我的所有子文件夹并将它们重命名为“example”。我不知道所有子文件夹的文件夹名称。我的代码根本不起作用。
文件夹结构示例:
Main Folder >Subfolder A > Subfolder 1 (Rename this)
>Some file
>Subfolder B > Subfolder 2 (Rename this)
>Some file
>...
这是代码:
Dim FSO As Object
Dim folder As Object
Dim subfolders As Object
Dim MyFile As String
Dim wb As Workbook
Dim CurrFile As Object
Dim NewFolderName As String
NewFolderName = "Photos"
With Application
.ScreenUpdating = False
.EnableEvents = False
.Calculation = xlCalculationManual
End With
Set FSO = CreateObject("Scripting.FileSystemObject")
Set folder = FSO.GetFolder("C:\Users\Tom\Desktop\Test\SHeets\")
Set subfolders = folder.subfolders
For Each folder In folder.subfolders
subfoldersName = folder.Path
Application.StatusBar = subfoldersName
Name subfoldersName As FolderName & NewFolderName ' change the folder name
Next
Set FSO = Nothing
Set folder = Nothing
Set subfolders = Nothing
With Application
.EnableEvents = True
.Calculation = xlCalculationAutomatic
.ScreenUpdating = True
End With
End Sub
解决方案
推荐阅读
- woocommerce - 在 WooCommerce 单品图片下显示自定义字段
- java - 为什么我的 Spring 3.2 混合配置会导致异常?
- solr - TYPO3 SOLR Cookie fe_typo_user
- c# - 使 Elasticsearch 变音符号不敏感
- ios13 - iOS 13 UIBackgroundTaskIdentifier
- javascript - 将字符串中的数组转换为数组
- python-3.x - KeyConditionExpression 接受无效输入并且不抛出异常
- multithreading - TidThreadComponent 的 Loop 属性
- node.js - 获取工作目录的管理员权限
- vue.js - vue scss 范围不适用于根元素