在word里面的vba运行,excel里的vba运行可能会出错
Sub kqbt_DelPar()
On Error Resume Next
Application.ScreenUpdating = False
Dim MyPath As String, newPath As String, i As
Integer, myDoc As Document
Dim myTitle$, myFileName$
Dim filename As String, OldName As String,
NewName As String
With
Application.FileDialog(msoFileDialogFolderPicker)
'选择存放word文档的文件夹,并将路径存放于myPath变量
.Title =
"选择源文件夹"
If .Show =
-1 Then
MyPath = .SelectedItems(1)
Else
Exit Sub
End If
End With
With Application.FileSearch
.LookIn =
MyPath
.FileType =
msoFileTypeWordDocuments
If .Execute
> 0 Then
For i = 1 To .FoundFiles.Count
filename = .FoundFiles(i)
MsgBox (filename)
OldName = filename
filename =
Replace(filename, "(", "")
filename =
Replace(filename, ")", "")
NewName = filename
Name OldName
As NewName
Next i
End If
End With
End Sub
参考
Sub 文件改名()
Dim OldName As String, NewName As String
OldName = ThisWorkbook.Path &
"\原文件名.txt"
NewName = ThisWorkbook.Path &
"\新文件名.txt"
Name OldName As NewName
End Sub
http://club.excelhome.net/viewthread.php?tid=435043