web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Word COM Objects - How to specify specific printer

(0) ShareShare
ReportReport
Posted on by 275

Hi Everybody

I am trying to print a word document, and i found this code (https://blogs.msdn.microsoft.com/czdaxsup/2009/09/08/howto-print-word-document-from-x/) which works fine. But i also need to specify a specific printer, it is using the default printer. Can anybody help?

I read something about using the method ActivePrinter to set the printer, but it does'nt seem to work. I get the error Method not exist.

I am using Word 2016.

----------------------------------------

str document = "C:\\test.doc";

COM wordApplication;

COM wordDocuments;

COM wordDoc;

str printerName = "\\\\H\\MyPrinter";

;

// Create instance of Word application

wordApplication = new COM("Word.Application");


// Get documents property

wordDocuments = wordApplication.Documents();


// Open document
wordDoc = wordDocuments.Open(document);

// Activate the document - this is necessary to print it

wordDoc.Activate();


// Print the document

wordDoc.PrintOut();


// Close document

wordDoc.Close();


// Close Word application

wordApplication.Quit();

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Martin Dráb Profile Picture
    237,880 Most Valuable Professional on at

    You can either change Application's ActivePrinter property or - if you don't want to change the default printer - call WordBasic.FilePrintSetup().

  • Ashein Profile Picture
    275 on at

    Hi Martin

    When i try to use active printer i get this error message 

    Printer error 

    And when i try to use FilePrintSetup i get this message

    My code is 

    COM wordApplication;

    COM wordDocuments;

    COM wordDoc;

    COM wordBasic;

    ;

    wordApplication = new COM("Word.Application");

    wordApplication.FilePrintSetup();

    // Or i tried this 

    // wordApplication.ActivePrinter(_printername);

    wordDocuments = wordApplication.Documents();



    wordDoc = wordDocuments.Open(_filename);



    wordDoc.Activate();



    wordDoc.PrintOut();



    wordDoc.Close(0);



    wordApplication.Quit();

  • Verified answer
    Martin Dráb Profile Picture
    237,880 Most Valuable Professional on at

    In the first case, you'll have to find out what kind of "printer error" it is. First of all, make sure that the printer name is correct and the printer is available.

    In the latter case, you're trying to call the method on a wrong object (Application instead of WordBasic).

  • Ashein Profile Picture
    275 on at

    Thanks Martin. It worked, the name were missing the prefix for print server.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans