Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2004-04-15
4
Medium Priority
?
528 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 1000 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…
Suggested Courses

972 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