Maximizing an active application...

Beastr0

New Member
Joined
Dec 28, 2004
Messages
22
I have the following code on a userform... I am trying to Restore the active application.. the following does work but it isn't very reliable to maximize on every try... is there anything I can use to maximize the activated application? This is not a microsoft program therefore I can't use the work, outlook, explorer objects...

Private Sub CWB_Click()
On Error GoTo NotOpen
AppActivate ("Corporate Workbench")
SendKeys "% R"
GoTo Done
NotOpen:
MsgBox ("You need to open application through L Bar First")
Done:
End Sub
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
This will likely be more dependable than sendkeys...

<table width="100%" border="1" bgcolor="White" style="filter:progid:DXImageTransform.Microsoft.Gradient(endColorstr='#C0CFE2', startColorstr='#FFFFFF', gradientType='0');"><tr><TD><font size="2" face=Courier New>  <font color="#0000A0">Option</font> <font color="#0000A0">Explicit</font>

  <font color="#0000A0">Private</font> <font color="#0000A0">Declare</font> <font color="#0000A0">Function</font> FindWindow <font color="#0000A0">Lib</font> "user32.dll" <font color="#0000A0">Alias</font> "FindWindowA" ( _
        <font color="#0000A0">ByVal</font> lpClassName <font color="#0000A0">As</font> String, _
        <font color="#0000A0">ByVal</font> lpWindowName <font color="#0000A0">As</font> String) <font color="#0000A0">As</font> <font color="#0000A0">Long</font>

  <font color="#0000A0">Private</font> <font color="#0000A0">Declare</font> <font color="#0000A0">Function</font> ShowWindow <font color="#0000A0">Lib</font> "user32.dll" ( _
        <font color="#0000A0">ByVal</font> hwnd <font color="#0000A0">As</font> Long, _
        <font color="#0000A0">ByVal</font> nCmdShow <font color="#0000A0">As</font> Long) <font color="#0000A0">As</font> <font color="#0000A0">Long</font>

  <font color="#0000A0">Private</font> <font color="#0000A0">Const</font> SW_MAXIMIZE <font color="#0000A0">As</font> <font color="#0000A0">Long</font> = 3

  <font color="#0000A0">Private</font> <font color="#0000A0">Sub</font> CWB_Click()
       <font color="#0000A0">Dim</font> MyAppsWindowHandle <font color="#0000A0">As</font> <font color="#0000A0">Long</font>

       MyAppsWindowHandle = FindWindow(vbNullString, "Corporate Workbench")

       <font color="#0000A0">If</font> MyAppsWindowHandle = 0 <font color="#0000A0">Then</font>
           MsgBox ("You need to open application through L Bar First")
           <font color="#0000A0">Exit</font> <font color="#0000A0">Sub</font>
       <font color="#0000A0">Else</font>
           <font color="#0000A0">Call</font> ShowWindow(MyAppsWindowHandle, SW_MAXIMIZE)
       <font color="#0000A0">End</font> <font color="#0000A0">If</font>

  <font color="#0000A0">End</font> <font color="#0000A0">Sub</font>
</FONT></td></tr></table><button onclick='document.all("1042006192153390").value=document.all("1042006192153390").value.replace(/<br \/>\s\s/g,"");document.all("1042006192153390").value=document.all("1042006192153390").value.replace(/<br \/>/g,"");window.clipboardData.setData("Text",document.all("1042006192153390").value);'>Copy to Clipboard</BUTTON><textarea style="position:absolute;visibility:hidden" name="1042006192153390" wrap="virtual">
Option Explicit

Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" ( _
ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long

Private Declare Function ShowWindow Lib "user32.dll" ( _
ByVal hwnd As Long, _
ByVal nCmdShow As Long) As Long

Private Const SW_MAXIMIZE As Long = 3

Private Sub CWB_Click()
Dim MyAppsWindowHandle As Long

MyAppsWindowHandle = FindWindow(vbNullString, "Corporate Workbench")

If MyAppsWindowHandle = 0 Then
MsgBox ("You need to open application through L Bar First")
Exit Sub
Else
Call ShowWindow(MyAppsWindowHandle, SW_MAXIMIZE)
End If

End Sub</textarea>
 
Upvote 0
Thanx, that worked great! Had to tweak it because it would only maximize the widow but not actually activate it... just added an appactivate line once the window was up
 
Upvote 0

Forum statistics

Threads
1,214,945
Messages
6,122,393
Members
449,081
Latest member
JAMES KECULAH

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