This is the known issue of x64 VBA macros. There is a workaround to forcibly make the SolidWorks window parent to the macro. Please refer the solution S-013887 in Knowledge Base. You may find the sample macro there.
You can also find a sample on Keith's web-site: http://www.cadsharp.com/macros/keep-vba-user-form-on-top-on-64-bit-systems-vba/
Happy New Year!
Application Engineer at Intercad
Tel: +61 2 9454 4444
Tom--- the macro on my site that Artem pointed to is a vastly simplified version of the macro provided in solution S-013887, so you may find it easier to work with. Also, it centers the user form in the middle the screen by first determining the height and width. Should you want to modify the placement, you will need to modify these lines:
lFormXval = sWinPlacementForm.rcNormalPosition.Right / 2
lFormYval = sWinPlacementForm.rcNormalPosition.Bottom / 2
'X and Y locations for form
lXval = lSolidWorksXval - lFormXval
lYval = lSolidWorksYval - lFormYval
Or update to 2013. I believe (according to what I've read) that the problem of forms popping up behind SW is due to VBA being 32 bit while SW is 64, so VBA has to run in a separate process that can't take focus.
Per the What's New, 2013 has a 64 bit version of VBA, so this problem should be solved. Caveat: I haven't tried this myself yet...
Thanks I got it all working.
I understand we have gotten back on maint and will be upgrading from 2011 to 2013.
Will I have to convert my macros to 64 bit?
If you have an api call that has a Long number you will need to convert your Longs to be 64 bit compatible. If the only api calls you have are in the module to put the form on top then you can remove the module and you should be fine.
I thought I would add more information in case a person uses api calls other that putting a form on top.
In one of my programs I use an api call to get the name of the computer that is running the program. Below is the code I used. It is written so that the program can be used in VBA or VBA7.
You can Google PtrSafe or Longptr for more complete information.
I hope this helps.
‘Written Dan Miel 10-16-2012
‘****If VBA7 use the first call or if VBA use the second.
#If VBA7 Then '11-16-2012
Declare PtrSafe Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As LongPtr) As LongPtr
Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
‘***Use this function to return the computer name.
Function UserName() As String
' Dimension variables
#If VBA7 Then '11-16-2012
Dim ret As LongPtr ', UserName As String
Dim ret As Long ', UserName As String
Dim lpBuff As String * 25
' Get the user name minus any trailing spaces found in the name.
ret = GetUserName(lpBuff, 25)
UserName = Left(lpBuff, InStr(lpBuff, Chr(0)) - 1)
' Display the User Name