Solved

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

Posted on 2004-04-15
4
519 Views
Last Modified: 2010-08-05
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?
0
Comment
Question by:Gordon_Atherley
  • 2
4 Comments
 

Expert Comment

by:denago
ID: 10839063
Try running the following command:
      rundll32.exe mshtml.dll,PrintHTML filename
0
 

Author Comment

by:Gordon_Atherley
ID: 10841279
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
0
 
LVL 17

Accepted Solution

by:
zzzzzooc earned 250 total points
ID: 10848716
Each application has it's own "Print" functionality. IE's "Print" just includes the dialog whereas Acrobat's doesn't. The "rundll32.exe" shortcut is basically the same as right-clicking on an HTML file and selecting "Print".

You should just use SendKeys() to automate the Print Dialog window. It's not "neat" but it should do the job.
0
 

Author Comment

by:Gordon_Atherley
ID: 10849246
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
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

821 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