First off, I could swear when I first developed my code (it was a few months
ago if I remember correctly), I thought I tried vbNullString (which is the
relatively standard thing to do) as the first argument to FindWindows and
that it didn't work, which is why I eventually settled on using
"ThunderDFrame"... but apparently I was wrong because vbNullString seems to
work fine, so I'm glad you brought this question up as I can now go back to
doing this the standard way.
Okay, the main problem in why your code isn't working is because you
declared the hWnd variable local to the Initialize event whereas my code
needs it declared in the (General)(Declarations) section of the UserForm's
code window (it is needed in two separate event procedures, so it must be
locally global at a minimum... your local declaration overrode my locally
global declaration). Try the following code which should work...
'*************** START OF CODE ***************
Private Declare Function FindWindow Lib "user32" _
Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long
Private Declare Function SetWindowLong& Lib "user32" _
Alias "SetWindowLongA" _
(ByVal hWnd As Long, _
ByVal nIndex As Long, _
ByVal wNewWord As Long)
Private Declare Function DrawMenuBar& Lib "user32" _
(ByVal hWnd As Long)
Private Declare Function SendMessage Lib "user32" _
Alias "SendMessageA" _
(ByVal hWnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
lParam As Any) As Long
Private Declare Function ReleaseCapture Lib "user32" () As Long
Private Const WM_NCLBUTTONDOWN = &HA1
Private Const HTCAPTION = 2
Dim hWnd As Long
Private Sub UserForm_MouseDown(ByVal Button As Integer, _
ByVal Shift As Integer, _
ByVal X As Single, ByVal Y As Single)
If Button = xlPrimaryButton And Shift = 1 Then
Call ReleaseCapture
Call SendMessage(hWnd, WM_NCLBUTTONDOWN, HTCAPTION, ByVal 0&)
End If
End Sub
Sub UserForm_Initialize()
hWnd = FindWindow(vbNullString, Me.Caption)
SetWindowLong hWnd, -16, &H84080080 ' remove caption
DrawMenuBar hWnd
SetWindowLong hWnd, -20, &H40000 ' remove borders
Call ListOpenWorkbooks
Listworksheets
Workbooks("Navigator").Sheets("Tables").Calculate
MultiPage1.Value = 0
End Sub
'*************** END OF CODE ***************