7

This is the code am using for zoomed out web browser

Const OLECMDID_OPTICAL_ZOOM = 63
Const OLECMDEXECOPT_DONTPROMPTUSER = 2

Web1.ExecWB OLECMDID_OPTICAL_ZOOM, OLECMDEXECOPT_DONTPROMPTUSER, CLng(35), vbNull

when i use the code i get the following runtime error:

-2147221248 (80040100): Automation Error

Any ideas?

Edited: I use the code given by you. It works fine in debug mode once i take exe and run it shows the following error.enter image description here

4
  • Works for me win7x64/IE9 but I can reproduce if I attempt the change when there is no loaded document; are you ensuring you only change the zoom after a document has loaded?
    – Alex K.
    Nov 14, 2012 at 11:22
  • Hi Alex, thanks for your reply. I am using a Microsoft web browser control to show an internet page on a form.How do i scale the page down to see it 35% smaller?
    – user1823492
    Nov 14, 2012 at 11:29
  • 2
    Are you ensuring you only change the zoom after a document has loaded?
    – Alex K.
    Nov 14, 2012 at 11:41
  • Alex, the Percentage of scaling the document happens at run time depends on the web browser size. i hard code the percentage of value (35%)smaller
    – user1823492
    Nov 14, 2012 at 11:52

1 Answer 1

3

This only works once a document has loaded, then seems to persist for subsequent navigation.

If you attempt to change the optical zoom when there is no DOM document, error 80040100 occurs.

The code below simply sets zoom initially at the appropriate time;

Private Const OLECMDID_OPTICAL_ZOOM As Long = 63
Private Const OLECMDEXECOPT_DONTPROMPTUSER As Long = 2

Private mblHasSetZoom As Boolean

Private Sub Form_Load()
    web1.Navigate2 "http://www.google.com"
End Sub

Private Sub web1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
If Not mblHasSetZoom Then
    web1.ExecWB OLECMDID_OPTICAL_ZOOM, OLECMDEXECOPT_DONTPROMPTUSER, 35&
    mblHasSetZoom = True
End If
End Sub
4
  • Alex, i just run the above code i got run time-error -2147221248 (80040100): Automation Error.The error message is method ExecWB of object "IWebBrowser2" failed
    – user1823492
    Nov 14, 2012 at 12:05
  • I'm not sure then, the only way I could get that error was when there was no doc, the example above works for me. What version if IE are you using?
    – Alex K.
    Nov 14, 2012 at 14:11
  • Hi Alex, am sorry the above code works in windows 95 but not works in windows 7 ultimate it shows the -2147221248 (80040100): Automation Error
    – user1823492
    Nov 14, 2012 at 14:26
  • I get the error as well even on first loading of the browser control. I just put in a kludge : On Error Resume Next and it works fine. Apr 10, 2017 at 23:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.