I have a workbook “A” with a macro and set with a shortcut “Ctrl+Q”, when I press “Ctrl+Q” the a form pops up, and when I press “ESC” the form is closed since I added a button “CommandButton1” whose property “Cancel” set to TRUE.
In the code I close the form like this:
Private Sub CommandButton1_Click()
Unload Me
End Sub
It works well, but the problem is I can’t switch to other opened workbooks until I close the workbook “A”, does anyone knows what the problem is?
thanks very much!
the code is like this:
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
The above form contains a webbrowser and a cancel button.
I added a button in a worksheet with the macro code Get_Photo.Show
when click the button, the form will show with a picture in it.
but when I closed the form after pressing “ESC”, I can’t then switch to other xlsm workbooks, but xlsx workbooks are fine..
I cannot explain the behavior. Probably it is a bug (However, I haven’t seen any documentation on it yet).
This will solve your problem. (TRIED AND TESTED)
Put this 2 extra lines of code in the button code of the worksheet from where you are calling the useeform.
HTH
Sid