用户窗体closures工作簿

我在Excel中创build了一个用户表单,所以当我打开xlsm文件时,只会打开用户表单,而工作簿是隐藏的。

但是,当我用[X]buttonclosures用户窗体时,我希望它closures工作簿和用户窗体而不保存。

当我现在closures用户表单,并尝试再次打开相同的文件,它说,它已经/ stil打开。

启动代码:

Private Sub Workbook_Open() Application.Visible = False Fordelinger.Show vbModeless End Sub 

closures代码:

 Private Sub Fordelinger_Deactivate() Application.Quit Workbooks("EstimatDOK.xlsm").Close True End Sub 

谁能帮忙? 🙂

您可以使用下面的代码来限制closures(X)button

 Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer) If CloseMode = 0 Then Cancel = True MsgBox "The X is disabled, please use a button on the form to Exit.", vbCritical End If End Sub 

要么

 Private Sub UserForm_Terminate() ThisWorkbook.Close savechanges:=False Application.Quit End Sub 

可能是您想在UserForm代码窗格中的此代码

 Private Sub UserForm_Terminate() ThisWorkbook.Close End Sub