0

I am using the following code to interact with an IE window. The code works perfectly IF the window has not been minimized and it just behind the other windows I have opened. If the user has minimized the IE window, then the things I am trying to do with IE do not fire. What can I add to un-minimize the window IF it is minimized. I would preferably like to leave the window in the same state (If the user has it maximized or sized to only cover a portion of the screen).

Public Declare Function SetForegroundWindow Lib "user32" (ByVal HWND As Long) As Long

Dim ie As Object
Dim GetIE As Object
Dim HWNDSrc As Long
Dim sIEURL As String

For Each GetIE In CreateObject("Shell.Application").Windows() 'Loop to find
If (Not GetIE Is Nothing) And GetIE.Name = "Internet Explorer" Then Exit For 'Found!
Next GetIE
GetIE.Visible = True 'Make IE window visible
Set ie = GetIE

HWNDSrc = ie.HWND
SetForegroundWindow HWNDSrc

'some code here



End Sub
Lzypenguin
  • 945
  • 1
  • 7
  • 18
  • Does this answer your question? [How can I maximize an IE window created by VBA with SHDocVw.InternetExplorer command?](https://stackoverflow.com/questions/41367209/how-can-i-maximize-an-ie-window-created-by-vba-with-shdocvw-internetexplorer-com) – braX Jan 28 '20 at 10:04
  • @braX I am not sure, but it looks like it might possibly. While trying to understand the code provided in the link, it looks like it is creating a new IE window, but I am trying to bring an existing window to front. I will continue to look into this, but if you have any insight on how i could incorporate this into my code that would be very helpful. – Lzypenguin Jan 28 '20 at 10:14
  • Have a look at this then... https://stackoverflow.com/questions/20664845/get-ie-window-object-by-window-title-with-vba – braX Jan 28 '20 at 10:19
  • @braX I am trying to look through the code in the provided responses and I think it will solve my problem, but I am not sure how to incorporate it into my code. I am not sure I fully understand (or want to incorporate into my code) a separate function and then calling that function during my macro. I will continue to look into these answers and try and incorporate it. Thank you for the help! – Lzypenguin Jan 28 '20 at 10:49
  • either way, you have to use the WINAPI to do it... there is no simple way it seems you are looking for – braX Jan 28 '20 at 11:17
  • @braX I am already using the WINAPI, but i am struggling to figure out how to add the other parts without messing up what i already have... – Lzypenguin Jan 28 '20 at 11:27

0 Answers0