Solved

Printing from Visual Basic using the Microsoft.Office.Interop.Word.Application. Colour required

Posted on 2010-09-08
3
1,251 Views
Last Modified: 2013-11-07
I have an application which prints a MS word document, however by default the selected printers print in 'Black and White' otherwise the user needs to select the colour option via the properties option.

Using the 'PrintDialog' option the user can view and select the properties required, however how can this be applied to MS word to print the document in colour?
Dim myWord As New Microsoft.Office.Interop.Word.Application
Dim myDoc As Microsoft.Office.Interop.Word.Document
Dim mySettings As New PrintDialog

If (mySettings.ShowDialog = Windows.Forms.DialogResult.OK) Then
   myWord.ActivePrinter = mySettings.PrinterSettings.PrinterName
   myDoc =    myWord.Documents.Open(strFilenames(intEmail).ToString)                                            myWord.ActiveDocument.PrintOut(Copies:=mySettings.PrinterSettings.Copies)
End if

Open in new window

0
Comment
Question by:Cmitch
3 Comments
 
LVL 9

Expert Comment

by:lwebber
ID: 33637092
You should be able to change the printer's default settings from the Control Panel. Exit Word. Open the printer's properties and change the selections to print in color. Start Word and look at the printer's settings. They should reflect what you defined as the defaults in the Control Panel.
0
 

Author Comment

by:Cmitch
ID: 33642015
Due to enforced policies their IT department has put in place to reduce costs the system won't save this change.  However users can print in color via MS Word if the select print and then make the settings change via the printer properties option.

How can do the via VB?
0
 
LVL 12

Accepted Solution

by:
omegaomega earned 500 total points
ID: 33780727
Hello, Cmitch,

In VB.Net you would probably need to do this through the GetHdevmode and SetHdevmode methods of the PrinterSettings class.  This is not going to be easy, since these methods return a pointer to a buffer, and dealing with pointers in VB is generally a little tricky.  To make matters more complicated, I guess the part of the buffer that controls colour printing will be at an offset that is specific to the printer in question.  If you have only one or two different types of printer to deal with, you might be able to find some documentation about this, or you may be able to figure it out by bringing up the printer's dialog, making the appropriate changes and trying to determine which parts of the buffer were affected... all very challenging.  

To make matters just a little messier, since you are printing via Word (and not directly via dotNet) you may find that you need to do all of this from Word itself.  This may require dynamically creating a Word macro to do all of this for you.   I'm not familiar with later versions of Word, but I suspect that you will need to use the APIs that are the equivalents of the PrinterSettings GetHdevmode and SetHdevmode methods.

All of this will be quite a lot of work.  I would probably review the need for this requirement with management and the users.  Perhaps as an alternative you could automatically open the printer's dialog box and have the users manually select colour or B&W.  That way, all the hard work and mysteries of the buffer offsets would be handled by the corresponding printer's driver.

Or perhaps someone else can give you a more encouraging suggestion.  

Cheers,
Randy
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Nice table. Huge mess. Maybe this was something you created way back before you figured out tabs or a document you received from someone else. Either way, using the spacebar to separate the columns resulted in a mess. Trying to convert text to t…
Introduction This tutorial provides instructions on how to properly format your Word document using the inbuilt tools provided. The benefits of using these tools means your documents are more accessible and easily portable to other applications an…
Learn how to create and modify your own paragraph styles in Microsoft Word. This can be helpful when wanting to make consistently referenced styles throughout a document or template.
This Micro Tutorial well show you how to find and replace special characters in Microsoft Word. This is similar to carriage returns to convert columns of values from Microsoft Excel into comma separated lists.

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question