내 진행률 표시줄의 Excel vba 사용자 양식에서 닫기 [X] 버튼 숨기기
매크로가 여전히 시트를 가져오는 중인 경우 진행 표시줄을 표시하기 위해 사용자 양식을 만들었습니다.
문제는 사용자가 빨간색 [X] 버튼을 누르면 처리가 중단된다는 것입니다.
잠재적인 사용자들이 실행되는 동안 클릭할 혼란스러운 버튼이 없도록 이 종말의 빨간 버튼을 숨길 수 있는 방법이 있을까요?
편집:
나 이거 먹어봤어요.
'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
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)
이 오류 메시지가 나타납니다.
이 코드는 여기서 가져온 것입니다.제가 뭘 잘못하고 있는지도 모르고 댓글도 이미 지웠어요.이것이 제가 찾은 가장 간단한 코드이기 때문에 제 사용자 양식에 통합하고 싶습니다.어떤 도움이든 감사히 받겠습니다.
다음은 다음과 같이 호출할 수 있는 루틴입니다.
subRemoveCloseButton MyForm
또는 양식 내에서:
subRemoveCloseButton Me
필요한 코드는 다음과 같습니다.
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
다음 토막글에서 해결할 수 있습니다.
선택합니다.cmdClose
메뉴 모음에서 버튼을 선택합니다.View | Code
커서가 깜박이는 곳에 다음 코드를 입력합니다.
Private Sub cmdClose_Click()
Unload Me
End Sub
메뉴 모음에서 다음을 선택합니다.View | Object
, 사용자 양식으로 돌아갑니다.
Esc 키를 눌러 양식을 닫을 수 있도록 하려면:
창에서 합니다 변경합니다. Properties(속성) 창에서Cancel
에의 재산.True
X 단추를 눌러 사용자가 양식을 닫지 못하도록 하려면
때.UserForm
열려 있습니다.X
우측 상단에 하는 것 에도 X를 수 .양식 닫기 버튼을 사용하는 것 외에도 X를 사용하여 양식을 닫을 수 있습니다.이를 방지하려면 다음 단계를 수행합니다.
User Form Choose(사용자 양식 선택)에서 빈 부분을 마우스 오른쪽 단추로 클릭합니다.View | Code
절차 드롭다운의 오른쪽 상단에서 쿼리 닫기를 선택합니다.
커서가 깜박이는 곳에 다음 샘플에서 강조 표시된 코드를 붙여 넣습니다.
Private Sub UserForm_QueryClose(Cancel As Integer, _
CloseMode As Integer)
If CloseMode = vbFormControlMenu Then
Cancel = True
MsgBox "Please use the Close Form button!"
End If
End Sub
메뉴 모음에서 다음을 선택합니다.View | Object
, 사용자 양식으로 돌아갑니다.만약 누군가가 그를 클릭한다면X
사용자 양식에 메시지가 표시됩니다.
http://www.contextures.com/xlUserForm01.html 에서
이것은 @Peter Albert의 위 답변을 개선한 것입니다.
- Windows API 호출은 이제 Office x64로 안전합니다.
FindWindow
Excel UserForms만 찾도록 통화가 개선되었습니다.원래 답변의 함수는 모든 창 클래스(예: 탐색기 창 및 다른 프로그램의 창)를 검색합니다.따라서 다른 프로그램이나 탐색기 창의 [x] 버튼이 사용자 양식과 이름이 같을 때 제거되었을 수 있습니다.
Private Const mcGWL_STYLE = (-16)
Private Const mcWS_SYSMENU = &H80000
'Windows API calls to handle windows
Private Declare PtrSafe Function FindWindow Lib "user32" Alias "FindWindowA" ( _
ByVal lpClassName As String, ByVal lpWindowName As String) As LongPtr
#If Win64 Then
Private Declare PtrSafe Function GetWindowLongPtr Lib "user32" Alias "GetWindowLongPtrA" ( _
ByVal hwnd As LongPtr, ByVal nIndex As Long) As LongPtr
Private Declare PtrSafe Function SetWindowLongPtr Lib "user32" Alias "SetWindowLongPtrA" ( _
ByVal hwnd As LongPtr, ByVal nIndex As Long, ByVal dwNewLong As LongPtr) As LongPtr
#Else
Private Declare PtrSafe Function GetWindowLongPtr Lib "user32" Alias "GetWindowLongA" ( _
ByVal hwnd As LongPtr, ByVal nIndex As Long) As LongPtr
Private Declare PtrSafe Function SetWindowLongPtr Lib "user32" Alias "SetWindowLongA" ( _
ByVal hwnd As LongPtr, ByVal nIndex As Long, ByVal dwNewLong As LongPtr) As LongPtr
#End If
Public Sub RemoveCloseButton(objForm As Object)
Dim lngStyle As LongPtr
Dim lngHWnd As LongPtr
Dim lpClassName As String
lpClassName = vbNullString
If Val(Application.Version) >= 9 Then
lpClassName = "ThunderDFrame"
Else
lpClassName = "ThunderXFrame"
End If
lngHWnd = FindWindow(lpClassName, objForm.Caption)
lngStyle = GetWindowLongPtr(lngHWnd, mcGWL_STYLE)
If lngStyle And mcWS_SYSMENU > 0 Then
SetWindowLongPtr lngHWnd, mcGWL_STYLE, (lngStyle And Not mcWS_SYSMENU)
End If
End Sub
ThunderDFrame?
Excel의 UserForms는 실제로 Windows 클래스입니다.ThunderDFrame
, 2002년 이후 Microsoft Office 응용 프로그램의 모든 UserFroms 클래스입니다.그 전에는.ThunderXFrame
.
버튼을 비활성화하는 유용한 방법은 다음과 같습니다.
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If CloseMode = 0 Then Cancel = True
End Sub
이것이 버튼을 제거하는 것은 아니지만, 버튼을 클릭하면 아무 것도 얻을 수 없습니다.
사용자에게 양식을 닫을 것인지를 묻습니다 - 그리고 편집을 잃을 것입니다.저스틴 & 피터의 아이디어를 바탕으로.
Private Sub UserForm_QueryClose(Cancel As Integer, _
CloseMode As Integer)
Dim ans
If CloseMode = vbFormControlMenu Then
Cancel = True
ans = Msgbox("Cancel edit?", vbQuestion + vbYesNo)
If ans = vbYes Then
Me.Hide
End if
End If
End Sub
편집: 사실 OP가 X 옵션을 제거하고 싶었기 때문에 이것이 약간 주제에서 벗어난 것임을 깨달았습니다. 하지만 여전히 대화형 양식에는 유용합니다.
이것이 오래된 질문이라는 것을 알고 있지만 인용한 OP의 사용자 양식의 경우 닫기 버튼을 제거하거나 숨기거나 비활성화할 필요가 없습니다.훨씬 더 간단한 방법이 있습니다 ;)
사용자가 상호 작용하는 요소가 없고(버튼 등) 목적이 완료되면 자동으로 닫히는 사용자 양식의 경우 양식을 비활성화해도 좋습니다.
사용자 양식을 비활성화하려면:사용자 양식의 속성에서 Enabled set False에 반대합니다.코드에서 숨기라고 할 때까지 사용자 양식이 표시됩니다.사용자는 양식에 대해 아무것도 할 수 없습니다(닫을 수 없음, 움직일 수 없음 등).
또한 사용자 양식이 표시되는 동안 기본 창에서 다른 작업을 수행할 수 있도록 할지 여부는 ShowModal을 설정할지 여부를 결정합니다.
언급URL : https://stackoverflow.com/questions/15153491/hide-close-x-button-on-excel-vba-userform-for-my-progress-bar
'source' 카테고리의 다른 글
휴대용 비교 및 스왑(원자 작동) C/C++ 라이브러리? (0) | 2023.10.24 |
---|---|
모든 요청에 대해 세션 시간 초과가 재설정됩니까? (0) | 2023.10.24 |
java.sql 푸는 방법SQL 비일시적 연결예외:결과 집합을 읽을 수 없습니다.연결 재설정? (0) | 2023.10.24 |
내부 기능에서 외부 기능을 종료할 수 있는 방법이 있습니까? (0) | 2023.10.24 |
Emacs에서 XML 파일을 예쁘게 인쇄 (0) | 2023.10.24 |