Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Select text in Word with VBA 1

Status
Not open for further replies.

Colvic

Programmer
Nov 4, 2005
24
0
0
NO
Hi,
Can anyone tell me how I can select text in Word with VBA.

I will select text between a start word and a end word.

Thanks in advance.
 
I don't really want to just hand something off to you, and you don't really give anything specific anyway. Select a word? A paragraph? A section? Have you looked in Help? This is very basic for programming.

It sounds like you are asking about a range - ie. from start to a end.

So look up Range.

What are you going to do with it? Again, look up Range, as it is generally better to work with a Range object, rather than Selection.

Do you need to FIND that start word, end word? You don't say, so...shrug...it may be inportant...it may not.

I strongly suggest you look in Help. There are a lot of examples of selecting and working with ranges. If you have something actually...hmmmm, specific...(rather than this kind of general question)....post back.

Gerry
My paintings and sculpture
 
Hi fumei.

Thanks for answering.

I want to select all text between a start word and a end word.
And then i will make a tabel or change font ect.


An example:

StartWord

This is an text I will mark,
between the start word an end word.
I have look in help, but I can not find what I look for.

EndWord
 
Additional information.

I will search for StartWord and EndWord and select all text between. I will make an macro (VBA) to do this.

Do you have any code example for this?
 

You could try recording yourself doing it manually but, for starters ...

Code:
[blue]Dim StartWord As String, EndWord As String
StartWord = "Start word"
EndWord = "End word"

With ActiveDocument.Content.Duplicate
    .Find.Execute Findtext:=StartWord & "*" & EndWord, MatchWildcards:=True
    .MoveStart wdCharacter, Len(StartWord)
    .MoveEnd wdCharacter, -Len(EndWord)
    .Font.Bold = True [green]' Or whatever you want to do[/green]
End With
[/blue]

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.

Professional Office Developers Association
 
How do you start numbering powerpoint slides without starting at "1
 
Look in File> Page setup.

There is a box just for this purpose.

For future reference, you really should start a new thread when asking a new question.

Lilliabeth
-Why use a big word when a diminutive one will do?-
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top