Hide close [X] button on excel vba userform for my progress bar

前端 未结 6 1471
面向向阳花
面向向阳花 2020-12-28 09:27

I created a userform to show a progress bar when the macro is still importing sheets \"enter

6条回答
  •  情话喂你
    2020-12-28 09:48

    Below is a routine that you can call like this:

    subRemoveCloseButton MyForm
    

    or from within your form:

    subRemoveCloseButton Me 
    

    Here's the code you'll need:

    Private Const mcGWL_STYLE = (-16)
    Private Const mcWS_SYSMENU = &H80000
    
    'Windows API calls to handle windows
    #If VBA7 Then
        Private Declare PtrSafe Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    #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 Long, ByVal nIndex As Long) As Long
    #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 Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
    #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
    
    
    Public Sub subRemoveCloseButton(frm As Object)
        Dim lngStyle As Long
        Dim lngHWnd As Long
    
        lngHWnd = FindWindow(vbNullString, frm.Caption)
        lngStyle = GetWindowLong(lngHWnd, mcGWL_STYLE)
    
        If lngStyle And mcWS_SYSMENU > 0 Then
            SetWindowLong lngHWnd, mcGWL_STYLE, (lngStyle And Not mcWS_SYSMENU)
        End If
    
    End Sub
    

提交回复
热议问题