question

BobbyJennings-9075 avatar image
0 Votes"
BobbyJennings-9075 asked emizhang-msft edited

Word 2016 Using Sendkeys in Autoopen

I would like to send a string to a word document when it opens.
But, sendkeys does not seem to work.

Here is my code.
Sub AutoOpen()
Application.GoBack
Selection.MoveDown Unit:=wdLine, Count:=10
Selection.MoveUp Unit:=wdLine, Count:=10
Call NavPaneSearch
SendKeys "Hi Mom"
End Sub

This should send "Hi Mom" to the newly open document, but it doesn't do it.

What will make this work?
Thanks!

office-vba-dev
· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.


Does it work if you execute Selection.TypeText "Hi, Mom" instead of SendKeys "Hi Mom"?


0 Votes 0 ·

Actually, I need to send a ctrl+key sequence.
But, I thought if I could get the text going, then I could try the ctrl+key.
Let me try that.

0 Votes 0 ·

Yes, that works.
Searching docs now to see if I can send a Ctrl+key sequence.

0 Votes 0 ·

0 Answers