0

I want to maximize IE by SW_MAXMIZE and then alert the user by prompting a msgbox. But since IE is maxmized, I want to bring Excel to the top by calling setforegroundwindow, but this statement is not working. Please help!

my code:

Public Declare PtrSafe Function apiShowWindow Lib "user32" Alias "ShowWindow" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Public Declare PtrSafe Function SetForegroundWindow Lib "user32" (ByVal hwnd As LongPtr) As Long
Public Const SW_MAXIMIZE = 3

sub try()
Set IE = New InternetExplorerMedium
IE.visible = True
apiShowWindow IE.hwnd, SW_MAXIMIZE
SetForegroundWindow Application.Hwnd 'Not working
Msgbox "IE Opened"
SetForegroundWindow IE.Hwnd
end sub
ellos98
  • 1
  • 2
  • try SW_SHOWNA instead of sw_maximize ... (SW_SHOWNA=8) – jsotola Aug 15 '17 at 02:35
  • btw: you did not actually ask a question, so people will guess what you want, and provide an answer for their guess. but you may not get what you wanted. – jsotola Aug 15 '17 at 02:38
  • @jsotola sorry, I want to maximize IE by SW_MAXMIZE and then alert the user by prompting a msgbox. But since IE is maxmized, I want to bring Excel to the top by calling setforegroundwindow, but this statement is not working. – ellos98 Aug 15 '17 at 02:47
  • so why don't you maximize the IE after you alert the user? – jsotola Aug 15 '17 at 03:00
  • why do you need to set Excel as foreground? – jsotola Aug 15 '17 at 03:02
  • @jsotola I am working on a developed tool in my company and the design is already implemented so I couldn't change it. Before we used SendKeys function to maxmize IE and the code works perfectly fine. But since some of the users complianted that we have to switch on numLock everytime we use SendKeys(old bug in VBA), I decided to use ShowWindow to maximize the window. However, setforegroundwindow suddenly doesn't work anymore thats why I am looking for a solution. – ellos98 Aug 15 '17 at 03:09
  • (a) Umm - stupid question I guess, but why don't the users **know** that IE has been opened when it becomes the foreground window? Why do they need a message to tell them that it has been opened? (b) FWIW - your code works for me. – YowE3K Aug 15 '17 at 04:11
  • try this for the message box `CreateObject("WScript.Shell").Run "mshta.exe vbscript:close(CreateObject(""WScript.shell"").Popup(""Internet Explorer has loaded"",3,""Message""))"` – jsotola Aug 15 '17 at 16:39

0 Answers0