|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
Sub 文件重命名()
Dim Arr, i%, oldName$, newName$
On Error Resume Next
Sheet1.Activate
Application.ScreenUpdating = False
Application.DisplayAlerts = False
If Range("A2") = "" Then MsgBox "没有数据", 64, "提示": Exit Sub
If Range("B1") = "原来的文件名" Then MsgBox "你已经重命名过文件了", 64, "提示": Exit Sub
Arr = Range("A1").CurrentRegion
' For i = 2 To UBound(Arr)
' If Len(Arr(i, 3)) = 0 Then MsgBox "请将第 " & i & " 行的新文件名填写完整!", 64, "提示": Exit Sub
' Next
For i = 2 To UBound(Arr)
oldName = Arr(i, 1) & Arr(i, 2) & Arr(i, 4)
newName = Arr(i, 1) & Arr(i, 3) & Arr(i, 4)
If Len(Arr(i, 3)) <> 0 Then
Name oldName As newName
End If
Next
Range("B1") = "原来的文件名"
Range("C1") = "现在的文件名"
MsgBox "重命名完成,请查看", 64, "提示"
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub |
|