Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
excel vba表单已关闭,但我可以';t切换到其他.xlsm工作簿_Excel_Vba - Fatal编程技术网

excel vba表单已关闭,但我可以';t切换到其他.xlsm工作簿

excel vba表单已关闭,但我可以';t切换到其他.xlsm工作簿,excel,vba,Excel,Vba,我有一个带有宏的工作簿“a”,并设置了快捷键“Ctrl+Q”,当我按“Ctrl+Q”时,会弹出一个表格,当我按“ESC”时,表格会关闭,因为我添加了一个按钮“CommandButton1”,其属性“Cancel”设置为TRUE 在代码中,我关闭表单,如下所示: Private Sub CommandButton1_Click() Unload Me End Sub VERSION 5.00 Begin {C62A69F0-16DC-11CE-9E98-00AA00574A4F} Get

我有一个带有宏的工作簿“a”,并设置了快捷键“Ctrl+Q”,当我按“Ctrl+Q”时,会弹出一个表格,当我按“ESC”时,表格会关闭,因为我添加了一个按钮“CommandButton1”,其属性“Cancel”设置为
TRUE

在代码中,我关闭表单,如下所示:

Private Sub CommandButton1_Click()
    Unload Me
End Sub
VERSION 5.00
Begin {C62A69F0-16DC-11CE-9E98-00AA00574A4F} Get_Photo 
   Caption         =   "abc"
   ClientHeight    =   3120
   ClientLeft      =   45
   ClientTop       =   435
   ClientWidth     =   4710
   OleObjectBlob   =   "Get_Photo.frx":0000
   StartUpPosition =   1  'CenterOwner
End
Attribute VB_Name = "Get_Photo"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False

Private Sub CommandButton1_Click()
    Unload Me
End Sub

Sub UserForm_Initialize()

    With Get_Photo
        .Caption = caption_Name
        .Width = 430
        .Height = 270
    End With

    With WebBrowser1
        .Width = 540
        .Height = 300
        .Navigate ("www.google.com/images/logos/images_logo_lg.gif")
    End With

End Sub
它工作得很好,但问题是我不能切换到其他打开的工作簿,直到我关闭工作簿“A”,有人知道问题是什么吗

非常感谢

代码如下所示:

Private Sub CommandButton1_Click()
    Unload Me
End Sub
VERSION 5.00
Begin {C62A69F0-16DC-11CE-9E98-00AA00574A4F} Get_Photo 
   Caption         =   "abc"
   ClientHeight    =   3120
   ClientLeft      =   45
   ClientTop       =   435
   ClientWidth     =   4710
   OleObjectBlob   =   "Get_Photo.frx":0000
   StartUpPosition =   1  'CenterOwner
End
Attribute VB_Name = "Get_Photo"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False

Private Sub CommandButton1_Click()
    Unload Me
End Sub

Sub UserForm_Initialize()

    With Get_Photo
        .Caption = caption_Name
        .Width = 430
        .Height = 270
    End With

    With WebBrowser1
        .Width = 540
        .Height = 300
        .Navigate ("www.google.com/images/logos/images_logo_lg.gif")
    End With

End Sub
上面的表单包含一个webbrowser和一个cancel按钮。 我在工作表中添加了一个按钮,宏代码为
Get\u Photo.Show
单击按钮时,表单将显示一张图片。 但当我按下“ESC”键关闭表单时,我无法切换到其他xlsm工作簿,但xlsx工作簿可以


@SiddharthRout,我添加了更多的评论来重现这个问题——aaron 30分钟前

最后,我能够复制它:)让我检查一下,然后再给你回复。我无法切换到其他xlsm/xlsx工作簿。它不断地向我展示原始工作簿。Alt+选项卡也拒绝工作。如果我按commandbutton,也不会有任何例外Siddharth Rout 1分钟前编辑

我无法解释这种行为。可能是一个bug(不过,我还没有看到任何关于它的文档)

这会解决你的问题。(经过尝试和测试

在调用UseForm的工作表的按钮代码中添加这两行额外的代码

Private Sub CommandButton1_Click()
    UserForm1.Show
    Application.ShowWindowsInTaskbar = False
    Application.ShowWindowsInTaskbar = True
End Sub


Sid

如果您的意思是在显示
UserForm
时无法切换书本,则这是正常的,因为默认情况下工作簿是模型。如果调用
UserForm
UserForm1.Show vbModeless
一样,则可以在活动
UserForm
期间切换书本。或者你是说在工作簿A关闭之前(即无论窗体是否打开),你都可以切换书本?@aaron:我无法重现这种行为。它在我的电脑上运行良好。我相信问题出在其他地方。你能发布用户表单和宏代码吗?@brettdj,谢谢,当对话框(非无模式)显示时,我们确实不能切换工作簿,但现在(抱歉描述不清楚),我的意思是在对话框关闭后切换工作簿。@Siddharth,谢谢,我将尝试用一个简单的工作簿复制,稍后会更新你。@SiddharthRout,我添加了更多的注释来重现这个问题