Automate Already Opened Browser Window


How to automate already Opened IE browser using excel Macros?

Steps:
Step 1: Open VBA editor on a new excel file and create a new module.
Step 2: Copy below code in the vba module.

Sub accessExistingIEBrowser()

      On Error Resume Next

      boolWindowFound = False
      Set objShell = CreateObject("Shell.Application")
      WinCount = objShell.Windows.Count
      For winNo = 0 To (WinCount - 1)

          strURL = objShell.Windows(winNo).document.Location
          strTitle = objShell.Windows(winNo).document.Title
          If strTitle Like "Sample Form" Then
              Set IE = objShell.Windows(winNo)
              boolWindowFound = True
              Exit For
          Else
          End If

      Next

      If boolWindowFound Then
        Set doc = IE.document
        doc.getElementsByName("fname")(0).Value = "test"
      End If

End Sub

Step 3: Run the module and enjoy :)