Solved

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

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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

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…
The Selection object is designed for user interaction. It has a Range property, so it can be used in most places that a Range object can. Recorded macros must use the Selection because they are simply copying what the user is doing. A Range prope…
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …

743 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

15 Experts available now in Live!

Get 1:1 Help Now