re-post border on userforms

N

new_to_vba

having trouble with the following code,

Private Sub UserForm_Initialize()
' Title bar is a skin -> resize UserForm dimensions
Me.Height = Me.InsideHeight + ((Me.Width - Me.InsideWidth) / 2)
Me.Width = Me.InsideWidth
hWnd = FindWindow(vbNullString, Me.Caption)
SetWindowLong hWnd, -16, &H84080080 ' No caption
SetWindowLong hWnd, -20, &H40000 ' No borders
End Sub

when i open my workbook i get a compile error, sub or function not defined.
with the findwindow highlighted.

any help would be great. new_to_vba
 
N

new_to_vba

Forgot to mention that this is a code given to me by Micheal Pieron.
sorry for not giving you credit for that Micheal, it was not my intention.
regards new_to_vba
 
N

NickHK

You do know that FindWindow and SetWindowLong are part of the windows API,
so VBA does not know anything about them ?
You have to include their declarations, so VBA can understand the call.

Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal
lpClassName As String, ByVal lpWindowName As String) As Long
Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal
hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long

The API-Guide from http://www.allapi.net/ will help you.

Also it may help if you defined constants for -16, -20, etc giving them a
descriptive name, so others (or yourself in 6 months time) can understand
what they mean and what you are trying to do.
e.g. Public Const WM_DRAWCLIPBOARD = &H308

NickHK
 
N

Nigel

FindWindow is a function that needs to be included in the userform code.
Where you sourced this code should have provided this as well.?
 
N

new_to_vba

seems like i am making one mistake after another,
here is the full code given to me. i think i have put it in the right places.
ie. "insert module" for the module section and in the userform for the
"userform initialize" section.

new_to_vba
 
N

new_to_vba

done it again forgot to include code.
try this.

In the UserForm module:

Private Declare Function FindWindow& Lib "user32" Alias _
"FindWindowA" (ByVal lpClassName$, ByVal lpWindowName$)
Private Declare Function SetWindowLong& Lib "user32" _
Alias "SetWindowLongA" (ByVal hWnd&, ByVal nIndex& _
, ByVal wNewWord&)
' If you want to be able to move UserForm
Private Declare Function ReleaseCapture& Lib "user32" ()
Private Declare Function SendMessage& Lib "user32" _
Alias "SendMessageA" (ByVal hWnd&, ByVal wMsg& _
, ByVal wParam%, ByVal lParam As Any)

Private hWnd&

' You need a button to close UserForm
Private Sub CommandButton1_Click()
Unload Me
End Sub

Private Sub UserForm_Initialize()
' Title bar is a skin -> resize UserForm dimensions
Me.Height = Me.InsideHeight + ((Me.Width - Me.InsideWidth) / 2)
Me.Width = Me.InsideWidth
hWnd = FindWindow(vbNullString, Me.Caption)
SetWindowLong hWnd, -16, &H84080080 ' No caption
SetWindowLong hWnd, -20, &H40000 ' No borders
End Sub

' If you want to be able to move UserForm
Private Sub UserForm_MouseDown(ByVal Button%, ByVal Shift%, ByVal X!, ByVal
Y!)
ReleaseCapture
SendMessage hWnd, &HA1, 2, 0&
End Sub
 
N

new_to_vba

i must be doing something wrong as i cant get either to work.
thanks anyway New_to_vba
 
N

NickHK

With API calls, you really should declare all functions with their return
value and check it.
Then you will know which call is failing.

NickHK
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top