Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1877
  • 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
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.

 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

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