admin管理员组

文章数量:1391778

I have a Userform1 where I try to remove the header and the 3d border that comes as default. The header part I have realized with a vba script. But the border part I couldn't make

According to Remove frame borders in userform I have first tried to set fmSpecialEffectFlat and fmBorderStyleNone manually in the form properties but still the border is there.

Then I have tried following code in a standard module but also not helped. The code just removes the caption ( I have called HideTitleBar from the initialising event of my form)

Option Explicit
Option Private Module

Public Const GWL_STYLE = -16
Public Const WS_CAPTION = &HC00000
#If VBA7 Then
    Public Declare PtrSafe Function GetWindowLong _
                       Lib "user32" Alias "GetWindowLongA" ( _
                       ByVal hwnd As LongPtr, _
                       ByVal nIndex As Long) As Long
    Public Declare PtrSafe Function SetWindowLong _
                       Lib "user32" Alias "SetWindowLongA" ( _
                       ByVal hwnd As LongPtr, _
                       ByVal nIndex As Long, _
                       ByVal dwNewLong As Long) As Long
    Public Declare PtrSafe Function DrawMenuBar _
                       Lib "user32" ( _
                       ByVal hwnd As LongPtr) As Long
    Public Declare PtrSafe Function FindWindowA _
                       Lib "user32" (ByVal lpClassName As String, _
                       ByVal lpWindowName As String) As LongPtr
#Else

#End If
Sub HideTitleBar(frm As Object)
    #If VBA7 Then
    Dim lFrmHdl As LongPtr
    #Else
    Dim lFrmHdl As Long
    #End If
    Dim lngWindow As Long
    lFrmHdl = FindWindowA(vbNullString, frm.Caption)
    lngWindow = GetWindowLong(lFrmHdl, GWL_STYLE)
    lngWindow = lngWindow And (Not WS_CAPTION)
    Call SetWindowLong(lFrmHdl, GWL_STYLE, lngWindow)
    Call DrawMenuBar(lFrmHdl)
End Sub

本文标签: userformHow can I remove the border of a user form in Excel 365 via vba codeStack Overflow