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

Announcements

No record found.

News and Announcements icon
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
    239,063 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
    239,063 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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Joris dG Profile Picture

Joris dG 5

#2
Andrew Jones a1x Profile Picture

Andrew Jones a1x 2

#3
GL-01081504-0 Profile Picture

GL-01081504-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans