页面打印输出Word VBS

问题描述

在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

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...