SendKeys Compile Error

jagrenet

Board Regular
Joined
Feb 23, 2022
Messages
81
Office Version
  1. 365
  2. 2013
  3. 2011
  4. 2010
Platform
  1. Windows
Hello,

I am attempting to use SendKeys in vba to "send" Enter to a Word doc. I keep getting a Compile error even after the variable is declared.
This code already lives inside a working Sub Routine, just want to "add" this function.

Dim SndEnter As Variant

Set SndEnter = Application.SendKeys("{ENTER}", True)

With
(working Application.Selection code

SndEnter
End With

"Compile Error - Expected Function or variable "

Not sure why this error is coming up.
Any ideas ??

Thanks in advance
 
First of all, this is not an Excel forum question, so, most likely, the thread will be moved elsewhere.

To select an entire sentence, try
VBA Code:
Selection.MoveRight Unit:=wdSentence, Count:=1, Extend:=wdExtend
You may want to set the Extend parameter to wdMove instead -- if you just need to move the cursor.
 
Upvote 0

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
First of all, this is not an Excel forum question, so, most likely, the thread will be moved elsewhere.

To select an entire sentence, try
VBA Code:
Selection.MoveRight Unit:=wdSentence, Count:=1, Extend:=wdExtend
You may want to set the Extend parameter to wdMove instead -- if you just need to move the cursor.
I have all of these procedures being performed from an Excel VBA Module which, is why I came here for help. I now have A huge gap from the beginning of the sentence to the last 4 words of the sentence. I am able to highlight ("Select") the 4 words using
.Next(Unit:=wdWord, Count:=13).Select ..... Then I have
.StartOf Unit:=wdParagraph, Extend:=wdMove ....... But the selection does not move and stays centered in the page. That's why I asked about potentially using "Justify". However, Justify does not appear as a method. I also tried "TypeBackSpace" but that did not work either.
 
Upvote 0
First of all, this is not an Excel forum question, so, most likely, the thread will be moved elsewhere.

To select an entire sentence, try
VBA Code:
Selection.MoveRight Unit:=wdSentence, Count:=1, Extend:=wdExtend
You may want to set the Extend parameter to wdMove instead -- if you just need to move the cursor.
Thank you for guiding me in the right direction. I FINALLY found the Format Method which permitted me to set the Selected text all the way to the Left, as it should be. ".Paragraphs.Format.Alignment = wdAlignParagraphLeft" -
 
Upvote 0
I can't believe you would need Sendkeys for this at all. I would think you would simply add a carriage return (or similar, Word not being my thing) to the document text.
I don't like using SendKeys at all but, at that particular point in time, that's all I had to reference. Thank you for jumping in to help out. I surely do appreciate your efforts !!
 
Upvote 0

Forum statistics

Threads
1,214,430
Messages
6,119,453
Members
448,898
Latest member
drewmorgan128

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top