简体   繁体   中英

Active printer problem in Printing word document through VB.net

My printer name is \\\\abc\\First Floor A-Block its taking name \\abc\\First Floor A-Block on NE04:. How should i print it

Private oWord As Word.Application

Dim lobjDoc As Word.Document

Dim strFolder as String
Dim pd As New PrintDocument
Dim strPrintername as String
oWord = CreateObject("Word.Application")
oWord.DisplayAlerts = Word.WdAlertLevel.wdAlertsNone
oWord.ActivePrinter =strPrintername 
strFolder="D:\testdoc.prn"

' Here I am giving the printer name which is on network, But its taking name

\\abc\\First Floor A-Block on NE04:

lobjDoc = oWord.Documents.Open(CType(strFolder, Object))

lobjDoc.PageSetup.FirstPageTray = Word.WdPaperTray.wdPrinterAutomaticSheetFeed

lobjDoc.PageSetup.OtherPagesTray = Word.WdPaperTray.wdPrinterAutomaticSheetFeed

lobjDoc.PrintOut(Background:=False, Append:=False, OutputFileName:=strFolder, PrintToFile:=True)  'here its giving error about printer settings

lobjDoc.Close(SaveChanges:=False)

Is there any way to print word document with all its content through PrintDocument ?

thanks

You can try this:

First use the Windows printer settings to set that printer as the default printer. Then open Word by hand and open the VBA editor, go to the immediate window and type ?ActivePrinter .

This should hopefully give you the exact format for the printer name that you need to send in for Word to recognize it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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