|
楼主 |
发表于 2022-3-30 17:53
|
显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
没有找到VBA控制PDF Shaper的资料,一定要用PDF Shaper的话就要用到API了吧。
好消息是,在找资料的时候发现了更牛的办法获取指定文件夹中所有PDF文件的页数,代码如下供参考。- Sub Test()
- Dim I As Long
- Dim xRg As Range
- Dim xStr As String
- Dim xFd As FileDialog
- Dim xFdItem As Variant
- Dim xFileName As String
- Dim xFileNum As Long
- Dim RegExp As Object
- Set xFd = Application.FileDialog(msoFileDialogFolderPicker)
- If xFd.Show = -1 Then
- xFdItem = xFd.SelectedItems(1) & Application.PathSeparator
- xFileName = Dir(xFdItem & "*.pdf", vbDirectory)
- Set xRg = Range("A1")
- Range("A:B").ClearContents
- Range("A1:B1").Font.Bold = True
- xRg = "File Name"
- xRg.Offset(0, 1) = "Pages"
- I = 2
- xStr = ""
- Do While xFileName <> ""
- Cells(I, 1) = xFileName
- Set RegExp = CreateObject("VBscript.RegExp")
- RegExp.Global = True
- RegExp.Pattern = "/Type\s*/Page[^s]"
- xFileNum = FreeFile
- Open (xFdItem & xFileName) For Binary As #xFileNum
- xStr = Space(LOF(xFileNum))
- Get #xFileNum, , xStr
- Close #xFileNum
- Cells(I, 2) = RegExp.Execute(xStr).Count
- I = I + 1
- xFileName = Dir
- Loop
- Columns("A:B").AutoFit
- End If
- End Sub
复制代码
|
评分
-
2
查看全部评分
-
|