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

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1849
  • Last Modified:

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
0
FrederikBonte
Asked:
FrederikBonte
  • 5
  • 2
1 Solution
 
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
 
BrianGEFF719Commented:
Ohhh my I am sorry:


    Const OLECMDID_PRINT = 6
    Const OLECMDEXECOPT_DONTPROMPTUSER = 2
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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
 
BrianGEFF719Commented:
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
 
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

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 5
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now