PDA

View Full Version : Need code to 'auto click' vba message



ma521
03-29-2017, 01:09 PM
I have some existing code that is displayed after a function is ran. After the user initiates a button click on the displayed popup it executes a series of key strokes. How can I edit the below code to have this process ran automatically without the user having to click?


Private Sub CommandButton1_Click() Unload Me

SendKeys "%", True
SendKeys "x", True
SendKeys "{ESC}", True
SendKeys "{ESC}", True

SendKeys "%", True
SendKeys "w", True
SendKeys "p", True

SendKeys "{ESC}", True
SendKeys "{ESC}", True
SendKeys "%", True
SendKeys "x", True
SendKeys "{ESC}", True
SendKeys "{ESC}", True

End Sub
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
'User clicked the X button on title bar
If CloseMode = 0 Then
bQuit = True
'Cancel the close
Cancel = True
Me.Hide
End If
End Sub
Private Sub CommandButton2_Click()
Unload Me

SendKeys "%", True
SendKeys "x", True
SendKeys "{ESC}", True
SendKeys "{ESC}", True

SendKeys "%", True
SendKeys "w", True
SendKeys "p", True

SendKeys "{ESC}", True
SendKeys "{ESC}", True
SendKeys "%", True
SendKeys "x", True
SendKeys "{ESC}", True
SendKeys "{ESC}", True
End Sub


Private Sub Frame1_Click()
Unload Me

SendKeys "%", True
SendKeys "x", True
SendKeys "{ESC}", True
SendKeys "{ESC}", True

SendKeys "%", True
SendKeys "w", True
SendKeys "p", True

SendKeys "{ESC}", True
SendKeys "{ESC}", True
SendKeys "%", True
SendKeys "x", True
SendKeys "{ESC}", True
SendKeys "{ESC}", True
End Sub

macropod
03-29-2017, 03:40 PM
Perhaps you could explain what those SendKeys commands are supposed to be doing. There's no way I'd run them to find out what happens on my system!

ma521
03-29-2017, 03:52 PM
Perhaps you could explain what those SendKeys commands are supposed to be doing. There's no way I'd run them to find out what happens on my system!
The send keys are simply navigating the Word ribbon through the ALT key to bring the user back to the Add-Ins tab after a function is ran that changes the layout of the word document (through the Layout tab).

The code that currently is in place has the user click a button and then runs the key stroke, I'm looking for a way to to do this without the user click.

macropod
03-29-2017, 07:12 PM
OK, but whatever you do, something on your userform is going to have to trigger the code's execution. You've already got 3 different methods of achieving the same thing - two command buttons and a frame click. What else does your userform contain/do that might serve as the trigger?

gmaxey
03-30-2017, 06:04 AM
The user must do something that calls your function or userform. At the end of whatever that something is call Park below

Sub Park()
SendKeys "%", True
SendKeys "x", True
SendKeys "{ESC}", True
SendKeys "{ESC}", True
SendKeys "%", True
SendKeys "w", True
SendKeys "p", True
SendKeys "{ESC}", True
SendKeys "{ESC}", True
SendKeys "%", True
SendKeys "x", True
SendKeys "{ESC}", True
SendKeys "{ESC}", True
End Sub