簡體   English   中英

VBA Excel 打印 Word Doc - 不打印

[英]VBA Excel Printing Word Doc - Not Printing

我的代碼在我自己的個人筆記本電腦上運行良好,代碼打開一個 Word 文檔並使用默認打印機打印它。

代碼是:

Private Sub CommandButton1_Click()    
    ' Step 1
    Dim objWord As New Word.Application
    ' Hidden window!
    objWord.Visible = False
    ' Save the original printer, otherwise you will reset the system default!
    Dim previousPrinter As String


    ' Step 2
    Dim objDoc
    Set objDoc = objWord.Documents.Open("test.docx")

    ' Step 3 -- in this case, print out the document without any prompts
    objDoc.PrintOut
    ' Restore the original printer
    objWord.ActivePrinter = previousPrinter

    ' Step 4
    objDoc.Close

    ' Step 5
    objWord.Quit
    MsgBox (objWord.ActivePrinter) 
End Sub

但是,當我在辦公室嘗試此操作時,代碼中沒有出現任何錯誤,但是沒有任何內容發送到打印機。 有什么可以導致這種情況的嗎? 它是一台施樂打印機(在網絡上),它使用跟隨打印

如果你強迫它在另一台打印機上打印,那么你需要這樣的東西:

previousPrinter = objWord.ActivePrinter

For i = 0 To 15
   curNePrint = VBA.Format(i, "00")
   On Error Resume Next
      objWord.ActivePrinter = "\\ServerName\printername z111b on ne" & curNePrint & ":"
Next i

objWord.PrintOut Copies:=1
ObjWord.ActivePrinter = previousPrinter
On Error Goto 0

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM