More on MS Word

Padawan

Active Member
Joined
Apr 9, 2002
Messages
395
Vlad (or anyone else)

May I impose on you for a little more help?

I simply want to add the word "ALL" at the beginning of a sentence. I currently have this code, Selection.Text:="ALL"
Selection.Delete Unit:=wdCharacter, Count :=3

I would like to enter the text ALL by overwriting the 3 spaces so I don't need the 2nd line of code.

Clear?

Thoughts?

THANK YOU
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Hi John,

Not clear what is in your selection.
If you select 3 spaces and willing to overtype "ALL" on selection then try:

'Overtype = True ' <-- set it if nothing is selected
Selection.TypeText Text:="ALL"
'Overtype = False

Vlad
 
Last edited:
Upvote 0
Or may be:
Rich (BB code):
Selection = Replace(Selection, "   ", "ALL")
' Or the same
Selection = Replace(Selection, Space(3), "ALL")
 
Last edited:
Upvote 0
Vlad

We're close.

I want to add text at the beginning of the line. The first word = ALL. I just want to have the curser in the home position of the line, and enter my text without moving the rest of the line to the right. Alternatively I can use the code I have then delete the same number of spaces as the character length of the word I enter. I was just hoping to write a slightly "cleaner" code.

I tried your sample, but it didn't work. I'm going to try using the macro recorder and hit the insert key to see what code it generates, but I believe I already tried that and it didn't work.
 
Upvote 0
Your 2nd post works if I select the first 3 spaces in the line. I would like to not have to select the 3 spaces.

Perhaps I'm too used to Excel macros where you usually don't need to select to write code.

Any other thoughts?

Thank you
 
Upvote 0
Try this:
Code:
  With Selection
    .HomeKey Unit:=wdLine, Extend:=wdMove
    .Words(1) = Replace(.Words(1), Space(3), "ALL")
  End With

or that:
Code:
  With Selection
    .HomeKey Unit:=wdLine, Extend:=wdMove
    .Words(1) = "ALL" & Mid(.Words(1), 4)
  End With
 
Last edited:
Upvote 0
Without changing of selection, using Range:
Code:
  With Selection.Paragraphs(1).Range
    .SetRange Start:=.Start, End:=.Start + 3
    .Text = "ALL"
  End With
 
Upvote 0
Vlad

For some reason I couldn't post back to this last night. Also couldn't send a PM.

I got the code to work, and wanted to THANK YOU for your help.
 
Upvote 0

Forum statistics

Threads
1,225,400
Messages
6,184,762
Members
453,255
Latest member
excelbit

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