Solved

Call Print Function from VB6.0 with file

Posted on 2004-04-05
8
1,793 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
  • 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
 

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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

707 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now