Solved

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

Posted on 2004-04-15
4
515 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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

760 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now