How do I switch back and forward between Excel and Internet Explorer

Scotchydog

New Member
Joined
Apr 27, 2022
Messages
2
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I am using Office 365 and am attempting to control a Terminal Style Internet Explorer Tab (Flynet Terminal Emulator).

I have the following code (below) which works perfectly so far to create an instance of IE, automatically log on and navigate to the correct menu.

What I would like to be able to do is to switch focus between Excel and IE via VBA Macros so I can fully control the terminal screen according to the user's needs.

I am sure there are better ways to do this via Chrome / Selenium etc. however I would prefer to stay within IE.

Just need to know how to switch focus and visibility back and forth between Excel and IE.

Cheers for any help.

Private Sub ControlFlynet()

Dim oIE As Object
Dim oHDoc As HTMLDocument
Dim DataObj As MSForms.DataObject
Set DataObj = New MSForms.DataObject

Set oIE = CreateObject("InternetExplorer.Application")

sSiteName = "https://flynet.dealer-services.com.au/nissan/"

' Open Internet Explorer Browser and keep it visible.
With oIE
.Visible = True
.Navigate sSiteName
End With

While oIE.ReadyState <> 4
DoEvents
Wend

Set oHDoc = oIE.Document

Application.Wait Now + TimeValue("00:00:10")

SendKeys ("S103150")
Application.Wait Now + TimeValue("00:00:01")
SendKeys ("{TAB}")
Application.Wait Now + TimeValue("00:00:01")
SendKeys ("Ftg1000")
Application.Wait Now + TimeValue("00:00:01")
SendKeys ("{ENTER}")
Application.Wait Now + TimeValue("00:00:01")
SendKeys ("V{ENTER}")
Application.Wait Now + TimeValue("00:00:01")
SendKeys ("V{ENTER}")
Application.Wait Now + TimeValue("00:00:01")
SendKeys ("C{ENTER}")


Application.Wait Now + TimeValue("00:00:01")
SendKeys ("^a")
Application.Wait Now + TimeValue("00:00:01")
SendKeys ("^c")
Application.Wait Now + TimeValue("00:00:01")

DataObj.GetFromClipboard

strpaste = DataObj.GetText(1)

oIE.Quit
SendKeys ("{ENTER}")

End Sub
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Add this at the top of the module, between Option Explicit (if present) and Private Sub ControlFlynet():

VBA Code:
#If VBA7 Then
    Private Declare PtrSafe Function SetForegroundWindow Lib "user32.dll" (ByVal hwnd As LongPtr) As LongPtr
#Else
    Private Declare Function SetForegroundWindow Lib "user32.dll" (ByVal hwnd As Long) As Long
#End If

And insert either of these lines where needed to switch to the required window:
VBA Code:
    SetForegroundWindow oIE.hwnd  'IE

    SetForegroundWindow Application.hwnd  'Excel
 
Upvote 0

Forum statistics

Threads
1,223,164
Messages
6,170,444
Members
452,326
Latest member
johnshaji

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top