doshivinod


Hello All,

I want to write a macro which will find a particular text in a word document.

(I know this has been discussed almost 100 times and is very easy)

But i want to access the actual found result inside the macro

or the next four chara of the found text.

e.g. (Document will contain the following text).

Pages : 2-3

Now i want to write a macro that will find the "Pages" word in document and will return me the value as "2-3".

Please help me on this.

(I am able to record a macro that will find a text and even tried to modify it but could not get the result which i needed)

I need it very urgently!!!

Many thanks for your kind help.

Vinod.




Re: Macro to FInd a Text and pick the next 4 chara of the found text.(or GET THE ACTUAL RESULT in side the macro)

Shasur


Hi

Here is one Hint. This would search for the text. You need to extend to required character to get the Page numbers

Code Snippet

Sub Pages()
Dim sText

Selection.HomeKey wdStory, wdMove
Selection.Find.Execute "Pages : ", False, False, False
Do While Selection.Find.Found = True
Selection.Collapse wdCollapseEnd
Selection.Expand Unit:=wdWord
sText = Selection.Text
Selection.ExtendMode = False
Selection.MoveRight
Selection.Find.Execute
Loop

End Sub

I you are proficient in Regular Expressions, I would advise you to go for that. You can give multiple forms of the Pages [0-9] combination and can extract data quickly

Cheers

Shasur







Re: Macro to FInd a Text and pick the next 4 chara of the found text.(or GET THE ACTUAL RESULT in side the macro)

doshivinod

Hi,

Many thanks for your reply!!!

It was really very helpfull for me as i am very new to all this.

Its really very intersting to play with these things.