Link to home
Start Free TrialLog in
Avatar of Gordon_Atherley
Gordon_Atherley

asked on

Inconsistent behavior of ShellExecute in printing pdf and htm files, using VB6

Help, please

I use the following to print documents from a VB6 app runing on Windows XP.

            ShellExecute hwnd, "PRINT", myPath2File, vbNullString, vbNullString, 0

If the document is .pdf, the printing is initiated, which is what I want.
If the document is .htm, the printers dialog box opens, which is not what I want.

Is there a way to avoid the printers dialog box, please?
Avatar of denago
denago

Try running the following command:
      rundll32.exe mshtml.dll,PrintHTML filename
Avatar of Gordon_Atherley

ASKER

Thanks Denago

I've tried the command in various ways, but I've succeeded only in generating error messages. This problem may well be my lack of knowledge. I've looked at KB 164787, and I'm unclear just how and from where I should run the command.

Please could you add a line or two to show how to handle it within VB6?

Thank you

Gordon
ASKER CERTIFIED SOLUTION
Avatar of zzzzzooc
zzzzzooc

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
zzzzzooc

Neat SendKeys() may not be, but functional it definitely is! Thank you.

This is what I used

     ShellExecute hwnd, "PRINT", sPathFile, vbNullString, vbNullString, 0
     Wait 5
     SendKeys "%(P)"

The Wait, set abitrarily at 5 sec, is needed to give the Print dialog box time to materialize. It does so fleetinglly. Then the automation proceeds as desired.

Acknowledgement, too, to Denago, for the alert to rundll32.exe, which I can see uses for in other ways.

Gordon