[VBA] Make AppActivate('d) window maximised

Snypa

New Member
Joined
Nov 1, 2013
Messages
45
Hello,

I have this code:

Code:
Sub OpenBrowserLink(link)

    Dim sh As Object, oWin As Object, IE As Object
    
    Set sh = CreateObject("Shell.Application")
    
    'Find an IE Window
    For Each oWin In sh.Windows
        If TypeName(oWin.Document) = "HTMLDocument" Then
            Set IE = oWin
            Exit For
        End If
    Next
    
    AppActivate IE.Document.title, True
    
    IE.navigate link, CLng(2048)

End Sub

It works as intended, finds a MSIE window, sets focus on it, opens a new tab. However, if the window is minimised, it does not maximise it. How can I achieve this? Google has not been helpful.
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Put this code at the top of the code module:
Code:
Private Declare PtrSafe Function ShowWindow Lib "user32" _
         (ByVal hwnd As LongPtr, ByVal nCmdSHow As Long) As Long
Const SW_SHOWMAXIMIZED = 3
Then, somewhere after your For loop, put this call:
Code:
ShowWindow IE.hwnd, SW_SHOWMAXIMIZED
 
Upvote 0
Great! I found something similar to this on google but I couldn't get it working. What you posted worked, many many thanks!
 
Upvote 0

Forum statistics

Threads
1,223,879
Messages
6,175,148
Members
452,615
Latest member
bogeys2birdies

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