Call Print Function from VB6.0 with file

Hi,

I need to make a call from VB6.0 to print an XML file (ordinary print) using the print from Internet Explorer (IE)

So i need something in the line of this

IE.Print filename,[printer]

The pages should run out of the printer without the user seeing IE or have to answer to a window with printersettings

Any answers?

Thx in advance

Frederik
FrederikBonteAsked:
Who is Participating?
 
BrianGEFF719Connect With a Mentor Commented:
Try this instead, add a internet exploerer control to your form.


webbrowser1.navigate2 "yourfile.xml"


Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
    pDisp.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER
End If
0
 
BrianGEFF719Commented:
go to project -> REFERENCES and check off microsoft internet controls


Private WithEvents IEObj As SHDocVw.InternetExplorer

Private Sub Form_Load()
   Set IEObj = New SHDocVw.InternetExplorer
   IEObj.Navigate "c:\yourxmlfile"
End SUb

Private Sub Form_Unload()
   Set IEObj = Nothing
End Sub

Private Sub IEObj_DocumentComplete(...)
   IEObj.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER
   Unload Me
End Sub



Just like that :)
-Brian
0
 
FrederikBonteAuthor Commented:
Can you give me the sytax of the command

OLECMDID_PRINT?
OLEXMDEXECOPT_DONTPROMPTUSER?

What do I put in the place of those two

Thx

Fred
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
BrianGEFF719Commented:
Ohhh my I am sorry:


    Const OLECMDID_PRINT = 6
    Const OLECMDEXECOPT_DONTPROMPTUSER = 2
0
 
FrederikBonteAuthor Commented:
When running in debug it works fine

But when running normal I get following

-2147221248:Method'ExecWB' or object 'IWebBrowser2' failed
0
 
BrianGEFF719Commented:
I found a solution, try this:


Public Function SendToPrinter() As Integer
   
    Dim tmpObject As Object
    Dim ptBrowser As WebBrowser  ' Object
   
    Set tmpObject = Forms(0).Controls.Add("Shell.Explorer.2", "WB1")
   
    ' for IE 6.x the browser control is wrapped in some kind of a outer wrapper
    ' so we need to access the inner object to get the browser, and set the outer to visible
    If TypeOf tmpObject Is WebBrowser Then
        Set ptBrowser = tmpObject
    Else
        Set ptBrowser = tmpObject.object
    End If
   
    ptBrowser.RegisterAsDropTarget = True
    ShowInBrowser ptBrowser

    tmpObject.Visible = True
    ptBrowser.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER, "", ""
    tmpObject.Visible = False
   
    Forms(0).Controls.Remove "WB1"

    SendToPrinter = 1
End Function

'-------------------------------------------------------
0
 
BrianGEFF719Commented:
I hope that helps.
0
 
StarklyCommented:
This is good.  However, what if I need to print to something other tyhan the default printer?  There was a workaround before IE6.0 where you could change the default printer through registry (Found on Microsoft I believe).  However, with IE6.0 this does not work.  Any suggestions?
0
All Courses

From novice to tech pro — start learning today.