Search code examples
excelinternet-explorermultiple-monitorsvba

How do you open IE on specified monitor using VBA in Excel?


I have code to center a userform on the active monitor. The userform has an option to open a fullscreens IE window which takes the user to a site and performs some HTML parsing. I would like to give the user the choice to open the IE window on the current or secondary monitor but I am not having luck finding any useful information online. The VBA I am using to open IE is shown below. Any pointers would be appreciated!

    Dim ie As Object
    Dim LoginAttempt As String
    Set ie = Nothing
    Set ie = New InternetExplorerMedium
    ie.Visible = False
    ie.Navigate "www.gooogle.com”

Solution

  • This might not be the most optimal way going about this, but it works for my application.

    Sub openBrowser()
    Dim ie As Object
    Dim Answ As Variant
    
    Set ie = CreateObject("InternetExplorer.Application")
    Answ = MsgBox("Do you want to open on scondary monitor?", vbYesNo)
    If Answ = vbYes Then ie.Left = 0
    ie.fullscreen = True
    ie.Visible = True
    ie.navigate "https://www.google.com"
    
    End Sub
    

    This works for me. Hope it helps you out

    /T