Link to home
Start Free TrialLog in
Avatar of spoowiz
spoowizFlag for United States of America

asked on

Problem printing to a specified printer.

I am trying to print documents from VB automatically to a printer using the following:
    Dim x
    x = ShellExecute(hwnd, "print", "index.htm", "'Printer1'", "C:\", 0)

What I want is to be able to print to a specified printer WITHOUT a printer dialog box.

I have a few problems with the above.
1. When printing "xxx.txt",
it prints to the "default" printer without a printer dialog box. (Not printing to the specified printer)
2. When printing "xxx.htm",
it brings up the printer dialog box. (I don't want the printer dialog box)
3. For some reason, printing "xxx.htm", the program doesn't print or show the printer dialog box, the FIRST time I execute the above stmt. The 2nd time on, it does show the printer dialog box as in #2.

Can you help?
thanks,
Phil
Avatar of spoowiz
spoowiz
Flag of United States of America image

ASKER

Never mind problem #3. The printer dialog box was behind other windows.
Avatar of nffvrxqgrcfqvvc
nffvrxqgrcfqvvc

You can always use the Microsoft Internet controls to do a print job.  As far as I know I don't think that you can print an HTM document with shellexecut. Also with the Internet control reference you can print it silently without any prompts.
ASKER CERTIFIED SOLUTION
Avatar of nffvrxqgrcfqvvc
nffvrxqgrcfqvvc

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
Avatar of spoowiz

ASKER

thanks. i'll try on monday.
Avatar of spoowiz

ASKER

egl1044 - i get a runtime error '430'. Class does not support Automation or does not support expected interfact.
at stmt: Set PrintFiles = New InternetExplorer

I double checked:
1. Dim WithEvents PrintFiles As InternetExplorer
2. MS Internet Controls

I'm using VB6, if it matters.
Thanks
Make sure you didn't add areference to Microsoft Transfer control, Make sure it is Microsoft Internet Controls
Also make sure its not the component you added, and its the reference to microsoft internet controls.

'Add this line Set PrintFiles = New InternetExplorer to Form_Load instead my bad
Avatar of spoowiz

ASKER

1. yes, MS Internet Controls for sure in References
2. Gives same error at same stmt in form_load

Dim WithEvents PrintFiles As InternetExplorer
Private Sub form_load()
    Set PrintFiles = New InternetExplorer
Do you have this line in the declerations section of the form?
Dim WithEvents PrintFiles As InternetExplorer
Avatar of spoowiz

ASKER

Yes. Just above form_load.
Avatar of spoowiz

ASKER

and the location of ms internet control is : c:\WINNT\system32\shdocvw.oca
i found another entry for Microsoft Internet Controls with location ..\system32\SHDOCVC.DLL.
i selected that also but error persists.
<<<---- ..\system32\SHDOCVC.DLL. this is the correct one
Avatar of spoowiz

ASKER

Tried again. Selected the 2nd also with same error. Perhaps it's another control?
No. Its just something else is conflicting with it.
Avatar of spoowiz

ASKER

I don't know how to unregister and register a dll.
Avatar of spoowiz

ASKER

i found it at EE. I'll try it and get back to you
Make sure that your on the user account you installed visual basic on.
To un-register and re-register simply to do this:

Click start run: type in: cmd for a command prompt
Un-Register:
type in: regsvr32 /u c:\windows\system32\shdocvw.dll

Re-register:
regsvr32 c:\windows\system32\shdocvw.dll


First close your project and start from scratch. Start new Standard.EXE project
Then add the reference
In your case it would be: my bad
regsvr32 /u c:\winnt\system32\shdocvw.dll
Avatar of spoowiz

ASKER

did it. no error with new project i created.
i removed it from "references" and components also had it so i removed it also.
saved project, restarted it and it's ok now. printed htm file file on "default" printer.
thank you. i can live with this.

any way to specifiy printer?
Thats good. Not sure however if you want a dialog to appear before the print so you can choose a printer then change this line : OLECMDEXECOPT_DONTPROMPTUSER to prompt user
Avatar of spoowiz

ASKER

Thank you for your help.
no problem. Thanks for the points.