VBA Userform Minimize problem

Sharad Singh

New Member
Joined
Jul 11, 2009
Messages
8
Hi All,

I have added the minimize button in VBA User form through API function. Now the problem is that whenever we start\open or switch to new excel work book the user form automatically popup and all the users have to again minimize it.

The code which I used for minimize:

Private Declare Function FindWindowA Lib "USER32" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long

Private Declare Function GetWindowLongA Lib "USER32" _
(ByVal hWnd As Long, _
ByVal nIndex As Long) As Long

Private Declare Function SetWindowLongA Lib "USER32" _
(ByVal hWnd As Long, _
ByVal nIndex As Long, _
ByVal dwNewLong As Long) As Long

Option Explicit

Sub FormatUserForm(UserFormCaption As String)

Dim hWnd As Long
Dim exLong As Long

hWnd = FindWindowA(vbNullString, UserFormCaption)
exLong = GetWindowLongA(hWnd, -16)
If (exLong And &H20000) = 0 Then
SetWindowLongA hWnd, -16, exLong Or &H20000
Else
End If

End Sub
</pre>
Thanks
Sharad Singh ;)
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Actually this application is used by 100 users for capturing the time. These all users also works on other excel files as well.
If I hide the form on minimize how will they recall it?
how we can add the recall button in tool bar ?? ;)
 
Upvote 0
Simple .. After you originally load it run
Code:
[I]Your Userform Name[/I].HIDE
Code:
[I]Your Userform Name[/I].SHOW

You can tie it to a shortcut key, or put it on the menu.. or trigger by an event..

Like

Code:
Private Sub Workbook_[B]BeforeClose[/B](Cancel as Boolean)
[I]      Your Userform Name[/I].SHOW   
End Sub
 
Upvote 0
Hi,

Thanks a lot .

But I am not sure that how can we tie it with shortcut key?
Or If I want to add the same in Standard tool bar as button for show and hide option for Form...
can you help me on this??
 
Upvote 0

Forum statistics

Threads
1,214,832
Messages
6,121,843
Members
449,051
Latest member
excelquestion515

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