Office 64 Bit code compatibility

I have an add-in that works in Word 32 bit but I'm having compatibility issue with Word 64 bit and I don't have a platform to test it with.  I've used the MS code compatibility checker, and made the changes suggested by it, but a remote user states that it still won't work.  The problem (at least one problem) appears to be in a code module that is used to "hide" the "X" button in a userform title bar.


I'm hoping that someone with Office 64 bit can evaluate/test this code to see if it works for them and if necessary correct so that it will work:


All you need is a new blank document and add a UserForm.  In a standard module named "FormControl" add this code:

Option Explicit
#If VBA7 Then
  Private Declare PtrSafe Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, _
        ByVal lpWindowName As String) As LongPtr
#Else
  Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
                                    (ByVal lpClassName As String, _
                                     ByVal lpWindowName As String) As Long
#End If
#If VBA7 Then
  Private Declare PtrSafe Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As LongPtr, _
                       ByVal nIndex As LongPtr) As LongPtr
#Else
  Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" _
                                       (ByVal hwnd As Long, _
                                        ByVal nIndex As Long) As Long
#End If
#If VBA7 Then
  Private Declare PtrSafe Function SetWindowLong Lib "user32" Alias "SetWindowLongA" _
                                         (ByVal hwnd As LongPtr, _
                                          ByVal nIndex As LongPtr, _
                                          ByVal dwNewLong As LongPtr) As LongPtr
#Else
  Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" _
                                       (ByVal hwnd As Long, _
                                        ByVal nIndex As Long, _
                                        ByVal dwNewLong As Long) As Long
#End If
Const WS_SYSMENU = &H80000
Const GWL_STYLE = (-16)


Sub HideCloseButton(oDialog As Object)
'Hides the close button on a userform
#If VBA7 Then
  Dim hwnd As LongPtr, lStyle As LongPtr
#Else
  Dim hwnd As Long, lStyle As Long
#End If
  'All userforms have class name "ThunderDFrame" unrelated to the form name.
  hwnd = FindWindow("ThunderDFrame", oDialog.Caption)
  lStyle = GetWindowLong(hwnd, GWL_STYLE)
  SetWindowLong hwnd, GWL_STYLE, lStyle And Not WS_SYSMENU
lbl_Exit:
  Exit Sub
End Sub


Add a command button to the userform and in the userform module add this code:


Private Sub UserForm_Activate()

  FormControl.HideCloseButton Me

End Sub


Private Sub commandbutton1_click()

  Unload Me

End Sub


Thanks.



Answer
Answer
The three userform works as expected on my system

Just remembering not to use FormControlAlternateHideX declarations on your projects at risk of crashing Word in runtime because of the handle issue.

---
https://www.mlf.net.br

Did this solve your problem?

Sorry this didn't help.

Great! Thanks for marking this as the answer.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this response?

Thanks for your feedback.

 
 

Question Info


Last updated April 19, 2018 Views 1,668 Applies to: