正如您所建议的那样,我已经进行了更改,但仍然无法使其变得用户友好,或者您可以说每次必须使用此代码时,都必须在不同计算机上打开脚本运行时。
请提出建议并尽快更正我的代码
Sub GetFileNamesandPageCount()
Option Explicit
Public fs As Object
Dim diaFolder As FileDialog
Set fs = CreateObject("Scripting.FileSystemObject")
Dim i As Integer
Dim fld As Object
Dim T_Str As String
Set diaFolder = Application.FileDialog(msoFileDialogFolderPicker)
diaFolder.AllowMultiSelect = False
diaFolder.Show
If diaFolder.Show = -1 Then
T_Str = diaFolder.SelectedItems(1)
Else
Set diaFolder = Nothing
End If
Set fld = fs.getfolder(T_Str)
Dim wdOBJ As Word.Application
Dim wdDoc As Object
Dim fd As Object
Sheet1.UsedRange.Clear
Sheet1.Range("A1") = "Document Name"
Sheet1.Range("B1") = "Page Count"
Sheet1.Range("A1:B1").Font.Bold = True
Sheet1.Columns("A:A").ColumnWidth = 70
Sheet1.Columns("B:B").AutoFit
Sheet1.Range("A1:B1").Interior.ColorIndex = 37
fs.GetSpecialFolder (1)
Set wdOBJ = CreateObject("Word.Application")
wdOBJ.Visible = True
i = 1
For Each fd In fld.Files
If (InStr(1, fd, ".doc") > 0) Or (InStr(1, fd, ".docx") > 0) Or (InStr(1, fd, ".docm") > 0) Or (InStr(1, fd, ".doct") > 0) Or (InStr(1, fd, ".pdf") > 0) Then
Sheet1.Range("A" & i + 1) = fd.Name
Set wdDoc = wdOBJ.Documents.Open(CStr(fd))
wdDoc.ComputeStatistics (wdStatisticPages)
Sheet1.Range("B" & i + 1) = wdDoc.BuiltinDocumentProperties(14)
wdDoc.Close False
End If
i = i + 1
Next fd
wdOBJ.Quit False
End Sub
1
我们不是代码审查网站,也不是Stackoverflow,这个问题不在
—
Superuser
欢迎来到超级用户。通常,这里的用户希望看到您尝试解决问题的方法,很显然您不是在问“嘿,有人会替我做我的工作吗?” 如果您添加一些细节来显示您已经尝试过的内容或所拥有的想法,但又不知道如何实现,则您更有可能获得支持和答复。
—
nixda