userform - How can I remove the border of a user form in Excel 365 via vba code? - Stack Overflow

I have a Userform1 where I try to remove the header and the 3d border that comes as default.The header

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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744764717a4592389.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信