Sub MyRenamePDF()
Dim MyFolder As String
Dim MyFile As String
Dim i As Long
Dim MyOldFile As String
Dim MyNewFile As String
Dim dt As String
Dim FSO As Object
Dim rng As Range
Dim dat As Variant
dt = Format(Now(), "YYYY_MM_DD_HH_MM")
Set FSO = CreateObject("Scripting.Filesystemobject")
MyFolder = "D:\test\"
TargetFolder = "D:\output\"
MyFile = Dir(MyFolder & "\*.pdf")
Do While MyFile <> ""
MyOldFile = MyFolder & "\" & MyFile
MyNewFile = MyFolder & "\" & "0001" & "_" & dt & "_" & MyFile
Name MyOldFile As MyNewFile
With ThisWorkbook.Worksheets("Logs")
Set rng = Range("B2:B100")
For Each cell In rng
If cell.Value = "" Then
cell.Value = MyNewFile
End If
Next cell
End With
FSO.MoveFile MyNewFile, TargetFolder
MyFile = Dir
Loop
End Sub
我在这个片段中遇到了一个问题:
With ThisWorkbook.Worksheets("Logs")
Set rng = Range("B2:B100")
For Each cell In rng
If cell.Value = "" Then
cell.Value = MyNewFile
End If
Next cell
End With