问题描述
在VBScript中运行时,我似乎无法让Words PrintOut
接受/兑现PAGES
的参数。奇怪的是,它很荣幸COPIES
。有什么想法吗?
代码:
Dim ObjWord
Set ObjWord = CreateObject("Word.Application")
ObjWord.Visible = True
'Open Document
Dim ObjDoc
'https://docs.microsoft.com/en-us/office/vba/api/word.documents.open
'.Open (FileName,ConfirmConversions,ReadOnly,AddToRecentFiles,PasswordDocument,PasswordTemplate,Revert,WritePasswordDocument,WritePasswordTemplate,Format,Encoding,Visible,OpenConflictDocument,OpenAndRepair,DocumentDirection,NoEncodingDialog)
Set ObjDoc = ObjWord.Documents.Open("C:\tmp\test.docx",TRUE,TRUE)
'PageRange
'https://docs.microsoft.com/en-us/office/vba/api/word.application.printout
'.PrintOut (Background,Append,Range,OutputFileName,From,To,Item,Copies,Pages,PageType,PrintToFile,Collate,FileName,ActivePrinterMacGX,ManualDuplexPrint,PrintZoomColumn,PrintZoomRow,PrintZoomPaperWidth,PrintZoomPaperHeight)
Dim ObjPrint
ObjPrint = ObjDoc.PrintOut(FALSE,"1",TRUE) ' No Error,but Pages not honored
'ObjPrint = ObjDoc.PrintOut(FALSE,"2",TRUE) ' Corretly Printes Two Copies
objDoc.Saved = TRUE
objWord.Quit
Set ObjDoc = Nothing
Set objWord = Nothing
解决方法
因此,我不得不通过一个附加参数来兑现Pages
的{{1}}值。
https://docs.microsoft.com/en-us/office/vba/api/word.document.printout https://documentation.help/MS-Office-Word-VB/womthPrintOut1.htm
它需要Range
声明。例如:
https://docs.microsoft.com/en-us/office/vba/api/word.wdprintoutrange
指定要打印的范围。
CONSTANT
就我而言,我相信它将永远是4。
因此,此操作按预期进行。 (仅打印第2页)
WDPRINTOUTRANGE ENUMERATION (WORD)
Name Value Description
wdPrintAllDocument 0 The entire document.
wdPrintCurrentPage 2 The current page.
wdPrintFromTo 3 A specified range.
wdPrintRangeOfPages 4 A specified range of pages.
wdPrintSelection 1 The current selection.
有关通过VBScript打印Word的更多信息。免责声明:这是我的个人博客-> https://www.freesoftwareservers.com/display/FREES/Print+Microsoft+Word+via+Batch+-+WINWORD.EXE+Switches+-+VBScript+Print+Specific+Pages