就是获取了文件夹名称和电脑的显示不一样,看看有没有大神,能不能帮忙解决一下。
图在二楼
代码如下:
Sub ①获取文件夹路径()
Dim objFSO As Object
Dim objFolder As Object
Dim objSubFolder As Object
Dim strPath As String
'设置目录路径
With ThisWorkbook.Sheets("文件夹改名")
colum_A_Max_Row = .Range("A" & .Rows.Count).End(xlUp).Row
If colum_A_Max_Row = 3 Then colum_A_Max_Row = colum_A_Max_Row + 1
.Range("A4:B" & colum_A_Max_Row).Value = ""
strPath = .[B1].Value
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(strPath)
'循环遍历目录下的所有文件夹
For Each objSubFolder In objFolder.SubFolders
.Range("A" & colum_A_Max_Row).Value = objSubFolder.Name '打印文件夹名称
colum_A_Max_Row = colum_A_Max_Row + 1
Next objSubFolder
colum_A_Max_Row = .Range("A" & .Rows.Count).End(xlUp).Row
.Range("A4:A" & colum_A_Max_Row & "").Sort Key1:=.Range("A1"), Order1:=xlAscending, Header:=xIYes
MsgBox "成功!", vbInformation, "提示"
End With
End Sub