如何在vba excel中只显示userform?

时间:2017-11-16 09:14:55

标签: excel vba excel-vba

我有一个在vba中创建的用户窗体,我想在打开excel时只显示用户窗体...有没有办法做到这一点..我已经尝试了代码,如

application.visible = false , activewindow.visible= false

如果我在打开之前在模块中使用此代码,那么已打开的文件将与我正在打开的文件一起隐藏 有人可以打电话给我,我怎么能特别隐藏我要打开的文件并显示用户形式

1 个答案:

答案 0 :(得分:2)

尝试这样的事情

1-创建一个带有2个按钮的用户表单(见下图)

enter image description here

2- ThisWorkbook代码

Private Sub CommandButton1_Click()
    If Workbooks.Count > 1 Then
        Windows("Test.xlsm").Visible = True
    Else
        Application.Visible = True
    End If
End Sub

Private Sub CommandButton2_Click()
    If Workbooks.Count > 1 Then
        Windows("Test.xlsm").Visible = False
    Else
        Application.Visible = False
    End If
End Sub

Private Sub UserForm_Initialize()
    If Workbooks.Count > 1 Then
        Windows("Test.xlsm").Visible = False
    Else
        Application.Visible = False
    End If
End Sub

Private Sub UserForm_Terminate()
    If Workbooks.Count > 1 Then
        Windows("Test.xlsm").Visible = True
    Else
        Application.Visible = True
    End If
End Sub

3-表格代码

host = "http://127.0.0.1:2375"

这只会显示或隐藏表单的工作簿。打开的任何其他工作簿都不会受到影响。