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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Word 2003 Macro

Status
Not open for further replies.

MrTBC

Technical User
Nov 19, 2003
610
US
Word 2003
Hi there.
I'm pretty good on VBA in Access but an absolutely amateur when it comes to VBA in Word.
I need a macro to do the following in a 300 page Word document please:
The macro needs to check each line of text to see if it is equivalent to:
99.99
(where 9 can be any number)
For each line like this it finds, it needs to add 1 to a counter and then display the result at the end in a message box.

Any ideas please?

Thanks very much.
 
The macro needs to check each line of text to see if it is equivalent to:
99.99
(where 9 can be any number)

"Equivalent"???????? What does that mean?

The quick brown fox jumps over the lazy dog.

...is equivalent to.....42? 98? 17?
For each line like this it finds, it needs to add 1 to a counter and then display the result at the end in a message box.
Display WHAT result????? For each line??? Hmmmmm, for a 300 page document, and a result for each line, that is going to be one very, very long message box. Or if not for each line - you end up with a counter of say (considering a 300 page document) 1152. What are you doing with that? What does it mean?

Gerry
 
Use Find and Replace ....

Ctrl+F to open the dialog
Click on More... to display the full dialog
Check "Use Wildcards"
Check "Highlight all items found in"
Select "Main Document" from the dropdown below the checkbox
In Find what, enter "<[0-9][0-9].[0-9][0-9]^13" (without the quotes)
Click on Find All
Word will highlight them all and a message appears within the dialog saying how many items it has found.

What that Find string looks for is find a 'word' in the format 99.99 terminated with a paragraph mark. You may want to replace the leading "<" with "^13" to find the numbers between two paragraphs - or tweak it in some other way to reflect exactly what you have in your 'lines'.

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
Excel VBA Training and more Help at VBAExpress[
 
Ah, I didn't realize it was an effort to matching literal strings...

Gerry
 
Thanks very much, I think Tony's suggestion will give me the answer.
 
Thanks very much - that worked perfectly.
OK. What I now need is a macro to do the following please (I know it's a strange request - don't ask!):

I now need a macro to work backwards through the document doing the following:
It should again search for lines of text that match the format:

99.99 (where 9 can be any number) followed by a paragraph mark

It should replace the first line of text that it finds that matches this format (i.e. the last one in the document) with:
23.59

The next should be 23.58, then 23.57, etc.
When it reaches 23.00 then the next line should be 22.59, etc.
i.e. like a 24 hour clock that becomes earlier through to the beginning of the document from 23.59

Thanks very much.
 
Try this:
Code:
[blue]Sub TimeReplace()
    
    Dim ReplaceTime As Date
    ReplaceTime = #11:02:00 PM#
    
    Selection.EndKey Unit:=wdStory
    
    With Selection.Find
        .ClearFormatting
        .Replacement.ClearFormatting
        .Text = "<[0-9][0-9].[0-9][0-9]^13"
        .Forward = False
        .Wrap = wdFindStop
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = True
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    While Selection.Find.Execute(ReplaceWith:=Format(ReplaceTime, "hh:mm") & vbCr)
        ReplaceTime = ReplaceTime - #12:01:00 AM#
    Wend

End Sub[/blue]

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
Excel VBA Training and more Help at VBAExpress[
 
Thanks very much.
It's nearly there but it starts with 23.02, not 23.59.
 
Sorry - I just tested it at that.

Change this line:
Code:
[blue]ReplaceTime = #[red]11:02:00 PM[/red]#[/blue]

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
Excel VBA Training and more Help at VBAExpress[
 
That's perfect.
Thank you very much for your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top