Solved

Call Print Function from VB6.0 with file

Posted on 2004-04-05
8
1,819 Views
Last Modified: 2008-02-01
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
Comment
Question by:FrederikBonte
[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
  • 5
  • 2
8 Comments
 
LVL 19

Expert Comment

by:BrianGEFF719
ID: 10756724
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
 

Author Comment

by:FrederikBonte
ID: 10756800
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
 
LVL 19

Expert Comment

by:BrianGEFF719
ID: 10756815
Ohhh my I am sorry:


    Const OLECMDID_PRINT = 6
    Const OLECMDEXECOPT_DONTPROMPTUSER = 2
0
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 

Author Comment

by:FrederikBonte
ID: 10756921
When running in debug it works fine

But when running normal I get following

-2147221248:Method'ExecWB' or object 'IWebBrowser2' failed
0
 
LVL 19

Expert Comment

by:BrianGEFF719
ID: 10756935
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
 
LVL 19

Expert Comment

by:BrianGEFF719
ID: 10756962
I hope that helps.
0
 
LVL 19

Accepted Solution

by:
BrianGEFF719 earned 125 total points
ID: 10756970
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
 

Expert Comment

by:Starkly
ID: 11095474
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

730 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