Link to home
Start Free TrialLog in
Avatar of mh2
mh2

asked on

Hiding Print Properties dialog

Hi,

I am trying to print an HTML page I built in a HTMLDocument object. However, this print must happen in the background, but the print properties dialog is always popping up.

Is there any way of getting rid of this dialog, and just letting the print go through as is with the default print properties?

I have tried:
mvarDocument.execCommand "Print", OLECMDEXECOPT_DONTPROMPTUSER, 0

and even:

Dim s As Variant
s = 0
mvarDocument.execCommand "Print", OLECMDEXECOPT_DONTPROMPTUSER, s

with no success at all, depsite what the MSDN says.

Does anyody have any ideas regarding this one?

Many thankx in advance,
Mark Hewitt
Avatar of Nitin Sontakke
Nitin Sontakke
Flag of India image

I am not too sure the object model you have mentioned. However, i have successfully done what you are trying to achieve using WebBrowser control (IE 6).

Here is the code i have used:

wbPrintHTML.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER

Hope it helps.
As long as i did read from MSDN, if you use IE version >5, it is not possible since IE overrides OLECMDEXECOPT_DONTPROMPTUSER parameter, but NitinSontakke saids the opossite :(
Avatar of mh2
mh2

ASKER

Hi,

Well, I know it can be done from a WebBrowser control as NitinSontakke says, despite the MSDN. The documentation seems a bit confusing on this matter.

I did alot of experimentation, and no success in a real sense. I did manage to create a hacked solution that works for me now. Not great I guess, but it'll do for the milestone demonstation on Friday.

What I did was create a WebBrowser control dynamically in the background, and use it to feed the print through. Talk about a hack hey! But it works for now.

Heres my code if you are interested...

'-------------------------------------------------

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

'-------------------------------------------------------

One thing I found, depending on your system, MS sometimes wraps the WebBrowse control returned in some funny outer wrapper. I thought it was just IE 6.x, but then I found a sstem with an identical IE version to mine, 5.5 something, and it also had this wrapper!

Thankx,
Mark
mh2, an EE Moderator will handle this for you.
Moderator, my recommended disposition is:

    Refund points and save as a 0-pt PAQ.
    *** mh2 -- I used that technique/hack in C++ Did you ever find a better way?

DanRollins -- EE database cleanup volunteer
ASKER CERTIFIED SOLUTION
Avatar of SpideyMod
SpideyMod

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial