简体   繁体   English

从 excel vba 的 word 文件中打印特定页面

[英]Print specific pages from word file from excel vba

I'm trying to print specific pages from a word file using Excel VBA, but I couldn't do that, I was only able to print the whole file and not the pages I wanted (changes according the value of LastPage).我正在尝试使用 Excel VBA 从 word 文件中打印特定页面,但我做不到,我只能打印整个文件,而不是我想要的页面(根据 LastPage 的值进行更改)。 This is the code I used.这是我使用的代码。 Please help with that, thanks.请帮忙,谢谢。

Sub PrintFile()
Dim objWord As Object
Dim objDoc  As Object

Set objWord = CreateObject("Word.Application")
Set objDoc = objWord.Documents.Open("D:file.docx")
objWord.Visible = False
objDoc.PrintOut from:="1", To:="LastPage".value
objWord.Quit
End Sub

Assuming you are getting an error on the line starting objDoc.PrintOut then replace that line with假设您在开始objDoc.PrintOut的行上遇到错误,然后将该行替换为

objDoc.PrintOut Range:=wdPrintFromTo, From:="1", To:=CStr(LastPage)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM