spoowiz
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
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
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks. i'll try on monday.
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
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
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
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
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
Dim WithEvents PrintFiles As InternetExplorer
ASKER
Yes. Just above form_load.
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.
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
ASKER
Tried again. Selected the 2nd also with same error. Perhaps it's another control?
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbenlr98/html/vamsgolenotsupported.asp
Unregister SHDOCVC.DLL then re-register
Unregister SHDOCVC.DLL then re-register
No. Its just something else is conflicting with it.
ASKER
I don't know how to unregister and register a dll.
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\shdocv w.dll
Re-register:
regsvr32 c:\windows\system32\shdocv w.dll
First close your project and start from scratch. Start new Standard.EXE project
Then add the reference
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\shdocv
Re-register:
regsvr32 c:\windows\system32\shdocv
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
regsvr32 /u c:\winnt\system32\shdocvw.
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?
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_DONTPROMPTUS ER to prompt user
ASKER
Thank you for your help.
no problem. Thanks for the points.
ASKER