0
votes

I try to embed web page into .xlsm Excel 2010 file. That what I have made so far :
In Sheet1 I've inserted ActiveX control called 'Microsoft Web Browser' its default name is WebBrowser1 (Developer->Insert->More Controls->Microsoft Web Browser). Then using VBA editor I placed following code into sheet module Sheet1 :

Private Sub Worksheet_Activate()
WebBrowser1.Navigate "http://stackoverflow.com/"
End Sub

I've tried various websites and html files placed on my local hard drive but the content displayed in WebBrowser1 control is always the same - 'Internet Explorer Cannot Display The Webpage' error with no error from Excel VBA alone. It seems that Microsoft Web Browser Object can't establish connection to web page.

2

2 Answers

7
votes

try this:

    'declare the web browser object for future reference and / or for listening to its events
    Dim WithEvents ie As WebBrowser

    'navigate when the worksheet is activated.
    Private Sub Worksheet_Activate()
        Set ie = ActiveSheet.WebBrowser1
        ie.Navigate2 "http://stackoverflow.com/"
    End Sub
-1
votes

After Navigate you have to put parenthesis maybe that's why it cannot read the site. It should be like

WebBrowser1.Navigate("http://www.stackoverflow.com")