|
本帖最后由 LMY123 于 2018-3-4 11:39 编辑
文件名称加上文件夹名称
- Sub test()
- Dim fso As Object
- Dim f1 As Variant
- Dim f2 As Variant
- Dim myname$
- Application.DisplayAlerts = False
- Set fso = CreateObject("Scripting.FileSystemObject")
- For Each f1 In fso.GetFolder(ThisWorkbook.Path).SubFolders
- For Each f2 In fso.GetFolder(f1.Path).Files
- myname = f1.Name & "." & Split(f2.Name, ".")(1)
- If Dir(f1.Path & "" & myname) = "" Then
- f2.Name = f1.Name & "-" & Split(f2.Name, ".")(0) & "." & Split(f2.Name, ".")(1)
- End If
- Next
- Next
- End Sub
复制代码 Sub renameas()
Dim fl As Object, obj As Object, mypath$
mypath = ThisWorkbook.Path
Set obj = CreateObject("scripting.filesystemobject")
Set fl = obj.Getfolder(mypath)
rena fl
End Sub
Function rena(fld As Object)
Dim subfl As Object
For Each f In fld.Files
If f.Name Like "*.xlsx" Then
f.Name = fld.Name & "-" & f.Name
Exit For
End If
Next
For Each subfl In fld.subfolders
rena subfl
Next
End Function
|
|