none
open a web page with VBA RRS feed

  • Question

  • Hi,

    I am trying to open a web page from an excel menu. I have found the 2 enclosed pieces of code on the web. But they both have the following problem:

    - they open Explorer and not the default browser

    - Microsoft displays a warning messages before opening the web browser (against potential virus, etc), if you click OK, fine. But if you click cancel, you get a VBA error.

    Any help really appreciated as usual.

    Thanks

    Caroline

    Sub LoadWebPage()

    ActiveWorkbook.FollowHyperlink

    Address:="http://www.rondebruin.nl/Google.htm"

    End Sub

    or

    Sub CallWebPage()
        ActiveWorkbook.FollowHyperlink _
            Address:="http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=225018&SiteID=1", _
            NewWindow:=True, _
            AddHistory:=True
        Application.WindowState = xlNormal
    End Sub

    Monday, January 14, 2013 8:29 PM

All replies

  • Hi Caroline,

    Thank you for posting in the MSDN Forum.

    Since your major concern is more related to using VBA language than Excel Object models, I'll move your thread to Visual Basic for Applications (VBA) for better support.

    Thank you for your understanding.

    Best regards,


    Quist Zhang [MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, January 15, 2013 10:21 AM
    Moderator
  • Caroline, try this...

    Sub WebPage()
                
            Dim IEapp As Object
            Dim WebUrl As String
            
            Set IEapp = CreateObject("InternetExplorer.Application") 'Set IEapp = InternetExplorer
            WebUrl = "http://www.google.com.au"
            
            'You can't really automate the passing of variables (ie. Login Name and Passwords) using Chrome or FireFox, but the below code will open the desired page
            Shell ("C:\Program Files (x86)\Google\Chrome\Application\chrome.exe -url " & WebUrl)  'Opens URL in Chrome if installed, replace chrome.exe with FireFox
                                                                                                    
            With IEapp
                .Silent = True 'No Pop-ups
                .Visible = True 'Set InternetExplorer to Visible
                .Navigate WebUrl 'Load web page
    
                'Run and Wait, if you intend on passing variables at a later stage
                Do While .Busy
                    DoEvents
                Loop
                
                Do While .ReadyState <> 4
                    DoEvents
                Loop
            
            End With
                   
        End Sub
    Enjoy...

    • Proposed as answer by Mr. Rik Sunday, January 20, 2013 9:53 AM
    • Unproposed as answer by Mr. Rik Sunday, January 20, 2013 9:53 AM
    • Proposed as answer by Pat0959 Monday, April 1, 2019 3:21 PM
    Thursday, January 17, 2013 1:20 AM
  • I don't see the purpose of opening both IE and google chrome, I should just use the shell function (and this doesn't work with the code above: you should go to the source of the application, this can vary).
    • Proposed as answer by Pat0959 Monday, April 1, 2019 3:21 PM
    Sunday, January 20, 2013 9:55 AM
  • I tend to use the following


    Option Explicit
    Private pWebAddress As String
    Public Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, _
                                                                                      ByVal lpOperation As String, ByVal lpFile As String, _
                                                                                      ByVal lpParameters As String, ByVal lpDirectory As String, _
                                                                                      ByVal nShowCmd As Long) As Long

    Public Sub NewShell(cmdLine As String, lngWindowHndl As Long)
        ShellExecute lngWindowHndl, "open", cmdLine, "", "", 1
    End Sub

    Public Sub WebPage()
        pWebAddress = "http://www.google.com.au"
        Call NewShell(pWebAddress, 3)
    End Sub


    Graham Mayor - Word MVP
    www.gmayor.com

    Sunday, January 20, 2013 12:30 PM
  • Sorry Rik, I was just showing her the difference between IE and Other browsers.  I should have commented as such

    Dangerous... #UpUpCronulla

    Sunday, January 20, 2013 9:47 PM
  • Graham:

    A bit late to the party, but I tried your code, substituting this for the web address:

    "http://journals.sagepub.com/action/doSearch?SeriesKey=pssa&AllField=" & Chr(34) & "structural+representation" & Chr(34)

    What the browser received, it seems, was:

    http://journals.sagepub.com/action/dosearch?serieskey=pssa&allfield="structural+representation"

    That is, all of the capped letters were converted to lower case, which broke the search.

    Any way around this?

    Thanks.


    • Edited by cyraxote Thursday, January 5, 2017 9:16 PM
    Thursday, January 5, 2017 9:15 PM
  • I copied the link from your post and included it in the macro

    Public Sub WebPage()
        pWebAddress = "http://journals.sagepub.com/action/doSearch?SeriesKey=pssa&AllField=" & Chr(34) & _
                      "structural+representation" & Chr(34)
        Call NewShell(pWebAddress, 3)
    End Sub
    
    

    and it made no changes to the case of the link?


    Graham Mayor - Word MVP
    www.gmayor.com

    Friday, January 6, 2017 12:07 PM
  • Well, I don't know what to say. I didn't make it up. But is that Firefox or Chrome in your screen cap? It looks like Firefox, because Chrome doesn't have the menu bar at the top. Maybe this is a Chrome issue.
    Friday, January 6, 2017 2:33 PM
  • It is Firefox. I don't use Chrome.

    Graham Mayor - Word MVP
    www.gmayor.com

    Saturday, January 7, 2017 4:48 AM