Solved

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

Posted on 2010-09-08
3
1,286 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

A few years ago I was very much a beginner at VBA, and that very much remains the case today.  I'll do my best to explain things as I go in the hope that other beginners can follow.  If you just want to check out a tool that creates a Select Case fu…
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
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.
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 …

717 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