Hello
In solidworks I created a macro button.
When I click on the button, the userform launches behind solidworks which is annoying for the user to have to look for the userform. (userform.show)
You then have to minimize the solidworks window and then re-open it so that the userform is displayed.
But it is only at the first opening that this problem appears...
Any idea?
Thanks in advance,
JB
I don't know too much about macros but maybe the beginning of an answer here
http://forum.hardware.fr/hfr/Programmation/VB-VBA-VBS/premier-plan-userform-sujet_77278_1.htm
or the
http://www.excel-downloads.com/forum/200197-garder-un-userform-au-premier-plan-de-lecran-windows.html
I hope I have been useful to you
Happydad
bart
April 2, 2014, 11:15am
3
Hello, we should add this line:
Application.WindowState = xlMinimized UserForm1.Show wbmodeless
Keep us informed! ;)
pl
April 2, 2014, 11:47am
4
Hello
A track to test:
Private Sub UserForm_Activate()
With Me
. StartUpPosition = 3
. Width = Application.Width
. Height = Application.Height
. Left = 0
. Top = 0
End With
End Sub
Spring:
http://www.commentcamarche.net/forum/affich-27509585-userform-reste-en-arriere-plan
Verify that the user form property ShowModal = True
But it's a known pb on some versions, you have to go through windows apis to force
The window in the foreground
in the declaration section
Private Declare Function FindWindow lib "user32.dll" aka "FindWindowA" ( _ ByVal lpClassName as String, _ ByVal lpWindowName as string) as long
Private Declare Function SetWindowPos Lib "user32" ( _ ByVal hwnd As Long, _ ByVal hWndInsertAfter As Long, _ ByVal X As Long, _ ByVal Y As Long, _ ByVal cx As Long, _ ByVal cy As Long, _ ByVal wFlags As Long) As Long
Private Const HWND_TOPMOST = -1
Private Const HWND_NOTOPMOST = -2
Private Const SWP_NOMOVE = &H2
Private Const SWP_NOSIZE = &H1
Private mlHwnd As Long
and in the activate of the form
SetWindowPos mlHwnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE Gold SWP_NOSIZE
7 Likes
Thank you for your answers,
Lucas
I ==> . Width = Application.Width
which created a runtime error '438'
Property or method not supported by this object
Jfaradon
SetWindowPos
makes me sub or function not defined
Bart
wbmodeless
variable not defined
On the other hand, now when solidworks is open when I activate windows (internet, word, excel...) they stay behind.
I think it's one of the solutions that modified a parameter (Jfaradon or Lucas)
It's true that my copy and paste was a bit fast; in addition it was necessary to correct in syntax 64
I but here is an example of a macro with this management via Windows API of the foreground
exemple_topmost.zip
6 Likes
Hello
Try a small:
Me.topmost=true
On my little apps in VB.Net it works.
Kind regards.
I forgot to mention that I program in VBA.
Maybe that's why these codes don't work...
The solidworks help does not know "topmost" or "SetWindowPos".
Classic but it should solve your problem:
http://support.microsoft.com/kb/184297/fr
FP