Excel VBA用户表单退出

时间:2018-10-23 08:03:46

标签: excel vba

我在Excel中有此用户表单。每次我关闭/退出用户窗体时,工作簿也会关闭。这正常吗?我对excel VBA或整个编码事物都非常陌生。如何防止/阻止这种情况的发生?我想发生的是,当我关闭用户窗体时,将在工作簿中显示某个工作表。

这是我的代码

Private Sub ExitForm_Click()
Sheets("Face").Activate
Unload PayrollSystem
End Sub

'To disable X button
 Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
 If CloseMode = 0 Then
    Cancel = True
    MsgBox "The X-button is disabled, there's an EXIT button on the form.", vbCritical
  End If

  End Sub

'To Add Minimize Button
Private Declare Function FindWindowA Lib "USER32" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long

Private Declare Function GetWindowLongA Lib "USER32" _
(ByVal hWnd As Long, _
ByVal nIndex As Long) As Long

Private Declare Function SetWindowLongA Lib "USER32" _
(ByVal hWnd As Long, _
ByVal nIndex As Long, _
ByVal dwNewLong As Long) As Long

Option Explicit

Sub FormatUserForm(UserFormCaption As String)
Dim hWnd            As Long
Dim exLong          As Long
hWnd = FindWindowA(vbNullString, UserFormCaption)
exLong = GetWindowLongA(hWnd, -16)
If (exLong And &H20000) = 0 Then
    SetWindowLongA hWnd, -16, exLong Or &H20000
Else
End If
End Sub

Private Sub UserForm_Initialize()

Call FormatUserForm(Me.Caption)

End Sub

0 个答案:

没有答案