回复 2# yu2n
非常感谢你的答复,但是我用vbs批量打印word档的部分页,代码如下:- input_pages = InputBox("要打印的页码和页码范围。例如:2, 6-10。表示打印第 2 页以及第 6 至第 10 页","word批量打印@徐飞专用版","整个文档")
- input_copies = InputBox("每个文档要打印的份数:","word批量打印@徐飞专用版","1")
-
- APP = "Word"
-
- Print_Dir App, SelectFolder
-
- Sub Print_Dir(APP,FolderPath)
- '本过程用于遍历目录下的文件,并打印
- Set fso = CreateObject("Scripting.FileSystemObject")
- Set AppObj = CreateObject(APP & ".Application")
- xxx1 = "doc" : xxx2 = "docx"
- AppObj.Visible = 0 :coun = 0
-
- If fso.FolderExists(FolderPath) Then
- Set Folder = fso.GetFolder(FolderPath)
- Set Files = Folder.Files
- fileNums = Files.Count
- time1 = Time
-
- For Each File In Folder.Files
-
- If right(File.name,3)= xxx1 Or right(File.name,4)= xxx2 then
- AppObj.Documents.Open(FolderPath & "\"& File.Name)
- AppObj.Windows(1).Activate
- If input_pages = "整个文档" then
- AppObj.PrintOut ,,,,,,,input_copies
- AppObj.Documents(1).Close False
- coun = coun +1
- Else
- AppObj.PrintOut ,,,,,,,input_copies,input_pages
- AppObj.Documents.Close False
- coun = coun +1
- End if
- End if
- Next
- time2 = Time
- MsgBox "共有文件" & fileNums & "个,打印文件" & coun & "个" & vbCrLf & "用时: " & DateDiff("s", time1, time2) & "秒"
- End if
- AppObj.Quit: Set AppObj = Nothing :Set fso = Nothing
- End Sub
-
- Function SelectFolder()
- Const WINDOW_HANDLE = 0
- Const OPTIONS = &H10
- Set objShell = CreateObject("Shell.Application")
- Set objFolder = objShell.BrowseForFolder _
- (WINDOW_HANDLE, "请选择你要打印的文件夹:", OPTIONS , "0")
-
- If objFolder Is Nothing Then
- Wscript.Quit
- End if
- Set objFolderItem = objFolder.Self
- SelectFolder = objFolderItem.Path
- Set objShell = nothing
- End Function
复制代码 运行后,输入打印要打印的页码,比如5-10,但打印的仍是整个文档。希望您为赐教,不胜感谢。 |