Solved

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

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

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…
Preface: When I started this series, I used the term CommandBars because that is the Office Object class that it discusses. Unfortunately, when Microsoft introduced Office 2007, they replaced the standard Commandbar menus with "The Ribbon" and rem…
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

829 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