|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
供参考:- Sub kk批量提取文档名称和页数()
- Dim wDia As FileDialog
- Dim n As Integer
- Dim wStr As String, wPat As String
- Dim wDoc As Document
- Dim fso As Object, tFil As Object
- Set wDia = Application.FileDialog(msoFileDialogFilePicker)
- With wDia
- .AllowMultiSelect = True
- .Filters.Clear
- .Filters.Add "Word文档", "*.doc;*.docx"
- If .Show = 0 Then Exit Sub
- Set fso = CreateObject("Scripting.FileSystemObject")
- wPat = fso.GetParentFolderName(.SelectedItems(1))
- For n = 1 To .SelectedItems.Count
- Set wDoc = Documents.Open(FileName:=.SelectedItems(n), Visible:=False)
- wStr = wStr & "Name " & wDoc.Name & vbTab & "Pages " & _
- wDoc.Range.Information(wdNumberOfPagesInDocument) & vbCrLf
- wDoc.Close False
- Next
- Set tFil = fso.opentextfile(wPat & "\TEMP.txt", 8, True)
- tFil.write wStr
- tFil.Close
- End With
- End Sub
复制代码 |
|