Question Locked

Printing a file in VBA

0 helpful
5 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

So in the program, I need to send a document (In this case an HTML document, but this could change in the future or be expanded on) to an imaging printer to be printed, wait for the conversion to finish, the grab the file and use it.

I know where the image will go, but how do I tell it to print something and which printer to print to.
Or do I need to create an instance of a browser object and tell it to navigate to that file, then tell it to print?

When I try searching online, all I find is something about a global printer object, but there is no global printer object or collection in our environment.

The solution cannot show the printing dialog, and the printer being printed to will not be the default printer.

Help?

5 replies

by tobif

I know MS believes Word can handle HTML.
So, do you want to print in Word?
(I'm just not sure whether VBA can directly control IE)

When you touch things a bit on the side, like printer selection etc, VBA suddenly is a bit tricky, but try to record a macro in Word, where you'd open the html doc you want, Select the correct printer and print, using print to file.

Then check what gets captured in that macro and how well it will repeat your actions.

by slayer_

I tried your solution, almost worked. It was a good idea but it made word specific code using word specific properties.

ChangeFileOpenDirectory "C:\CFW32\"
   Documents.Open FileName:="output.html", ConfirmConversions:=False, _
      ReadOnly:=False, AddToRecentFiles:=False, PasswordDocument:="", _
      PasswordTemplate:="", Revert:=False, WritePasswordDocument:="", _
      WritePasswordTemplate:="", Format:=wdOpenFormatAuto, XMLTransform:=""
   ActivePrinter = "Print-2-Image"
   Application.PrintOut FileName:="", Range:=wdPrintAllDocument, Item:= _
      wdPrintDocumentContent, Copies:=1, Pages:="", PageType:=wdPrintAllPages, _
      ManualDuplexPrint:=False, Collate:=True, Background:=True, PrintToFile:= _
      False, PrintZoomColumn:=0, PrintZoomRow:=0, PrintZoomPaperWidth:=0, _
      PrintZoomPaperHeight:=0                                                                                                              

It also wrote very badly formatted code, but that's a different topic :).

Our VBA environment is custom, which makes it VERY hard to find help on the internet, as VBA is immediately associated with Word and excel or access. And VB6 has its own global objects for printing.

by tobif

...but i works well as inspiration.

by slayer_

I was able to give the proposed project a thumbs up

This discussion is closed to new replies.