Printing a file in VBA

By Slayer_ ·
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.


This conversation is currently closed to new comments.

Thread display: Collapse - | Expand +

All Answers

Collapse -

MS Word, or...?

by TobiF In reply to Printing a file in VBA

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.

Collapse -

You gave me an unrelated idea, so you get a thumb but

by Slayer_ In reply to MS Word, or...?

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, _

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.

Collapse -

I never said the autogenerated code is neat

by TobiF In reply to You gave me an unrelated ...

...but i works well as inspiration.

Collapse -

Well it Semi worked

by Slayer_ In reply to I never said the autogene ...

I was able to give the proposed project a thumbs up

Related Discussions

Related Forums