在我的进度条上隐藏excel vba userform上的关闭[X]按钮 [英] Hide close [X] button on excel vba userform for my progress bar

查看:1043
本文介绍了在我的进度条上隐藏excel vba userform上的关闭[X]按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个用户窗体,当宏仍在导入工作表时显示一个进度条



问题是用户可以按下红色 [X] 按钮,关闭并中断处理完成。 >

有没有办法隐藏这个emom的红色按钮,这样潜在的用户在运行时就不会有任何混乱的按钮来点击。



编辑:



我尝试过这个

 '查找userform的窗口
私有声明函数FindWindow Libuser32_
别名FindWindowA(_
ByVal lpClassName As String,_
ByVal lpWindowName As String)As Long

'获取当前窗口样式
私有声明函数GetWindowLong Libuser32_
别名GetWindowLongA(_
ByVal hWnd As Long,_
ByVal nIndex As Long)As Long

'设置新窗口样式
私有声明函数SetWindowLong Libuser32_
别名 SetWindowLongA(_
ByVal hWnd As Long,_
ByVal nIndex As Long,_
ByVal dwNewLong As Long)As Long

Const GWL_STYLE = -16
Const WS_SYSMENU =& H80000

我在userform_initialize

  Dim hWnd As Long,lStyle As Long 

'哪种类型的userform
如果Val(Application.Version)> = 9然后
hWnd = FindWindow(ThunderDFrame,Me.Caption)
Else
hWnd = FindWindow ThunderXFrame,Me.Caption)
End If

'获取当前窗口样式并关闭关闭按钮
lStyle = GetWindowLong(hWnd,GWL_STYLE)
SetWindowLong hWnd,GWL_STYLE,(lStyle而不是WS_SYSMENU)

我收到此错误消息



此代码取自 here 。我不知道我做错了什么,我已经删除了评论。这是我发现的最简单的代码,所以我想将它集成到我的用户窗体。任何帮助都不胜感激。

解决方案

以下是一个可以这样调用的例程:

  subRemoveCloseButton MyForm 

或从您的形式:

  subRemoveCloseButton Me 

以下是您需要的代码:

  Private Const mcGWL_STYLE =(-16)
Private Const mcWS_SYSMENU =& H80000

'Windows API调用处理窗口
#If VBA7然后
私有声明PtrSafe函数FindWindow Libuser32别名FindWindowA(ByVal lpClassName As String,ByVal lpWindowName As String)As Long
#Else
私有声明函数FindWindow Libuser32别名FindWindowA(ByVal lpClassName As String,ByVal lpWindowName As String)As Long
#End如果

#如果VBA7然后
私有声明PtrSafe函数GetWindowLong Libuser32别名GetWindowLongA(ByVal hwnd As Long,ByV Al nIndex As Long $ as $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $

#如果VBA7然后
私有声明PtrSafe函数SetWindowLong Libuser32别名SetWindowLongA(ByVal hwnd As Long,ByVal nIndex As Long,ByVal dwNewLong As Long)As Long
#Else
私有声明函数SetWindowLong Libuser32别名SetWindowLongA(ByVal hwnd As Long,ByVal nIndex As Long,ByVal dwNewLong As Long)As Long
#End如果


Public Sub subRemoveCloseButton(frm As Object)
Dim lngStyle As Long
Dim lngHWnd As Long

lngHWnd = FindWindow(vbNullString,frm.Caption)
lngStyle = GetWindowLong(lngHWnd,mcGWL_STYLE)

如果lngStyle和mcWS_SYSMENU> 0然后
SetWindowLong lngHWnd,mcGWL_STYLE,(lngStyle And not mcWS_SYSMENU)
End If

End Sub


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

The problem is the user can press the red [X] button that will close and interrupt the processing done.

Is there a way to hide this red button of doom so that potential users don't have any confusing buttons to click while it runs.

edit:

I have tried this

'Find the userform's Window
Private Declare Function FindWindow Lib "user32" _
        Alias "FindWindowA" ( _
        ByVal lpClassName As String, _
        ByVal lpWindowName As String) As Long

'Get the current window style
Private Declare Function GetWindowLong Lib "user32" _
        Alias "GetWindowLongA" ( _
        ByVal hWnd As Long, _
        ByVal nIndex As Long) As Long

'Set the new window style
Private Declare Function SetWindowLong Lib "user32" _
        Alias "SetWindowLongA" ( _
        ByVal hWnd As Long, _
        ByVal nIndex As Long, _
        ByVal dwNewLong As Long) As Long

Const GWL_STYLE = -16
Const WS_SYSMENU = &H80000

and I used this on userform_initialize

   Dim hWnd As Long, lStyle As Long

   'Which type of userform
   If Val(Application.Version) >= 9 Then
      hWnd = FindWindow("ThunderDFrame", Me.Caption)
   Else
      hWnd = FindWindow("ThunderXFrame", Me.Caption)
   End If

   'Get the current window style and turn off the Close button
   lStyle = GetWindowLong(hWnd, GWL_STYLE)
   SetWindowLong hWnd, GWL_STYLE, (lStyle And Not WS_SYSMENU)

I am getting this error message

this code was taken from here. I don't know what I'm doing wrong and I already removed the comments. This is the simplest code that I found so I would like to integrate it to my userform. Any help is appreciated.

解决方案

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

这篇关于在我的进度条上隐藏excel vba userform上的关闭[X]按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆