|
普通处理可试试如下代码:- Sub test()
- Dim myDialog As FileDialog
- Dim mypath As String
- Dim a As String
- Dim myfilename() As String
- Dim i As Integer
-
- On Error Resume Next
- Set myDialog = Application.FileDialog(msoFileDialogFilePicker)
- myDialog.Title = "请指定目标文件夹"
- If myDialog.Show <> -1 Then Exit Sub
- mypath = myDialog.InitialFileName
- a = Dir(mypath & "*.doc*")
- Do While a <> ""
- ReDim Preserve myfilename(i)
- myfilename(i) = a
- i = i + 1
- a = Dir
- Loop
-
- Application.ScreenUpdating = False
- For i = 0 To UBound(myfilename)
- With Documents.Open(mypath & myfilename(i))
- .Range(0, 0).InsertAfter Left(myfilename(i), InStrRev(myfilename(i), ".") - 1) & vbCrLf
- With .Paragraphs.First '首个段落格式设置,如:
- .Style = wdStyleHeading1
- .Alignment = wdAlignParagraphCenter
- With .Range.Font '首个段落字符格式设置,如:
- .Size = 16
- .NameFarEast = "方正小标宋简体"
- End With
- End With
- .Close wdSaveChanges
- End With
- Next
-
- MsgBox "共处理了" & UBound(myfilename) + 1 & "个文档。", vbInformation
- Application.ScreenUpdating = True
- End Sub
复制代码 |
|