Solved

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

Posted on 2010-09-08
3
1,245 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Do you ever need to create a 20 page Word document for some testing purpose? Are you tired of copying & pasting old boring "lorem ipsum" text over and over again, increasing font size and line space in order to make the document 20+ pages long? Look…
Introduction Authors who set out to write any sort of lengthy piece for online submission—be it a long question or comment on a technical form, an article, or a substantial blog entry—often find it useful to work up a draft in an editor other t…
This video walks the viewer through the process of creating envelopes and labels, with multiple names and addresses. Navigate to the “Start Mail Merge” button in the Mailings tab: Follow the step-by-step process until asked to find the address doc…
In a previous video Micro Tutorial here at Experts Exchange (http://www.experts-exchange.com/videos/1358/How-to-get-a-free-trial-of-Office-365-with-the-Office-2016-desktop-applications.html), I explained how to get a free, one-month trial of Office …

920 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now