[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

VB6 OLE Automation using IE to print HTML document without user intervention...

Posted on 2004-08-11
5
Medium Priority
?
2,431 Views
Last Modified: 2010-05-18
Summary of needs:
1 - print an HTML document without opening a window and making the user click File -> print...
2 - would like to have the option of bypassing or showing the printer dialog window.
3 - would like to have this happen "in the background", like it does when you right-click on an HTML file and select print from the menu (without IE windows opening and closing).

Goals 2 and 3 are not a requirement, but would be nice to have.  I am trying to use OLE Automation, but it doesn't have be this way.  If you have a better method of accoplishing these tasks, please let me know (maybe "rundll32" with a shell command?).

I can't get goal 1 to work using OLE Automation. I am trying to do this using VB 6 and OLE Automation with the InternetExplorer.Application object.  I found some documentation on MSDN (http://msdn.microsoft.com/workshop/browser/webbrowser/reference/objects/internetexplorer.asp).  From what I read, it tells me that I can get an Document object then get a Window object, then use the print() method.  It doesn't work, and it seems to be the only method in the Window object that doesn't.  The following is a listing of the simple code:

<code>
On Error GoTo openDoc_Err
    Dim IE As Object, win As Object
   
    Set IE = CreateObject("InternetExplorer.Application")  'create the object
   
    IE.Visible = True
    IE.Navigate "http://msdn.microsoft.com/workshop/author/dhtml/reference/objects/obj_window.asp"
    While IE.Busy = True
        DoEvents
    Wend
   
    Set win = IE.Document.parentwindow
    win.Print
   
    While IE.Busy = True
        DoEvents
    Wend
   
    MsgBox "done!"
   
 
openDoc_Exit:
    Screen.MousePointer = vbNormal
    Set IE = Nothing
    Set win = Nothing
    Exit Sub

openDoc_Err:
    MsgBox "ERROR -" + CStr(Err.Number) + ": " + Err.Description
    Resume openDoc_Exit

</code>

The URL in the code should take you directly to the page that lists the methods for the Window object.  I must be mis-reading.

Thanks!

0
Comment
Question by:kkennedy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
5 Comments
 
LVL 34

Expert Comment

by:flavo
ID: 11780570
to print without user intervention use


Const OLECMDID_PRINT = 6
Const OLECMDEXECOPT_DONTPROMPTUSER = 2

  oIE.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER


0
 
LVL 34

Expert Comment

by:flavo
ID: 11780581
to not show IE (ie poping up), just dont use oIE.Visable = true.  be sure to close it with oIe.QUIT when done
0
 
LVL 34

Accepted Solution

by:
flavo earned 500 total points
ID: 11780592
Const OLECMDID_PRINT = 6
Const OLECMDEXECOPT_DONTPROMPTUSER = 2
 Dim IE As Object, win As Object
   
    Set IE = CreateObject("InternetExplorer.Application")  'create the object
   
    IE.Visible = True
    IE.Navigate "http://msdn.microsoft.com/workshop/author/dhtml/reference/objects/obj_window.asp"
    While IE.Busy = True
        DoEvents
    Wend
   
   IE.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER

    While IE.Busy = True
        DoEvents
    Wend
   
    MsgBox "done!"

   IE.quit
  set IE = nothing

As i side note, i think i had problems with closing IE before it printed, i dont think IE.Busy works for printing... i cant really remember...

Dave
0
 

Author Comment

by:kkennedy
ID: 11784290
Thanks Dave, you get the points!

Where do I find documentation on this?  I found some documentation, but I can't seem to find how you knew that the command id was 6.  How would I find the value of other commands and options?
0
 
LVL 34

Expert Comment

by:flavo
ID: 11788641
I cant remember sorry, i think msdn.  did it a while ago, didnt keep a list of the other ones...

Dave
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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

650 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