SendKeys behavior is erratic...

Post Reply
americanaustralian
Posts: 21
Joined: Sat Jul 13, 2013 7:50 pm
Location: Manteca, CA USA

SendKeys behavior is erratic...

Post by americanaustralian »

When I use SendKeys, and I run the script using F8 to step through it, the SendKeys commands don't work. If I run the script using F9, the first instance works, the second doesn't do what's expected, and the third causes a system alert beep, otherwise does nothing at all.

Here's the script:

Sub Main

' ***** Declare Variables In Subroutines *****

' ***** Assign PlanMaker object *****

Set pm = CreateObject("PlanMaker.Application")

' ***** Using an existing Workbook *****

pm.Visible = True
pm.Activate

SendKeys "No Action" 'Sent text to cell as expected
MsgBox "Action text sent"

' CTRL-h is to open the Search and Replace Dialog

SendKeys "^h", True 'Appended "h" to the same cell as above
MsgBox "Ctrl-h sent" 'Apparently no CTRL was sent

' ALT-l is to trigger Replace All in the Search and Replace Dialog

SendKeys "%l"
MsgBox "Alt-l sent"

Set pm = Nothing

End Sub
SuperTech
SoftMaker Team
SoftMaker Team
Posts: 2933
Joined: Wed Mar 11, 2020 5:31 pm

Re: SendKeys behavior is erratic...

Post by SuperTech »

I have checked the script and this is not working because of the following problems:

1. Once you execute

SendKeys "No Action"

It activates the cursor position inside the activate cell which makes the next statement

SendKeys "^h"

Non-executable because this can execute only when cursor is not in the cell. To avoid this please send Enter Key after that so the code will be:

SendKeys "No Action" 'Sent text to cell as expected
SendKeys "{Enter}"

2. After opening the Search dialog box using

SendKeys "^h"

you opened another message box which disturbed next statement for sending Alt+l

SendKeys "%l"

Please test the following code with F9 after corrections. This will add "No Action" and then replace "No" with blank:

Code: Select all

Sub Main

' ***** Declare Variables In Subroutines *****

' ***** Assign PlanMaker object *****

Set pm = CreateObject("PlanMaker.Application")

' ***** Using an existing Workbook *****

pm.Visible = True
pm.Activate

SendKeys "No Action" 'Sent text to cell as expected
SendKeys "{Enter}"   

SendKeys "^h", True 'Appended "h" to the same cell as above
SendKeys "No"

SendKeys "%l"


Set pm = Nothing

End Sub
americanaustralian
Posts: 21
Joined: Sat Jul 13, 2013 7:50 pm
Location: Manteca, CA USA

Re: SendKeys behavior is erratic...

Post by americanaustralian »

Didn't occur to me to exit the cell first. Thank you for the solution...
Post Reply

Return to “BasicMaker 2018 for Windows”