Finding, and editing, text in a Word document?

J.Windebank

Registered User.
Local time
Today, 15:18
Joined
Apr 2, 2003
Messages
37
OK, this my trickiest problem yet I fear.

In my application we enter dfata into a form, and then hit a command button, and it creates a word file from the date based on a number of SQL queries.

The problem is that there are a few choice words in the document that need to be made one size smaller.

Now here is an example of one part of the document:

Morning (before 12 noon)

WorldWatch International News..808
Sunrise..709
National Nine Early News..904
Aerobics Oz Style..089
Business Breakfast..205
Today..952
Good Morning Australia..053
Mornings with Kerri-Anne..554
Seven Morning News (10.30am)..657
Ricki Lake..740
National Nine Morning News (11am)..911
Huey's Cooking Adventures..005
Fresh..585
Ten Morning News (11:30am)..015

They are actually TV shows we have here in Melbourne.

I need to go through once the page has been created, and the find all data that is in brackets, and make it one font size smaller.

I assume I can somehow use the "Find" function in Word to find the first bracket, create a selection through to the last bracket, and then change the font size property.

The main problem I have is, I have absolutely no idea how to use the Range/Selection functions. Can anyone offer any advice, examples or references I can check please?

Thanks,

Jordan
 
I don't have time to look into this in detail, but I have messed with Word a little. I'll give you the code I wrote in case the reference will help. The following function took a long document that had forced carriage returns every 55 characters and removed the carriage return. It also bolded chapter headings. I did this a long time ago, and it was the only time I had to interface with Word, so I don't remember much about it. However, I do recall that if you hit Alt+F11 and look at the VBA help file in Word, there is a lot of good information and examples.

Code:
Sub FormatDocument()
    Dim Blanks As Integer
    Dim Length As Integer
    Dim ParString As String
    Dim Char As String
        
    For i = 2 To 100000
        Length = Len(ActiveDocument.Paragraphs(i).Range)
        If Length = 1 Then
            Blanks = Blanks + 1
        Else
            Length = Len(ActiveDocument.Paragraphs(i - 1).Range)
            ParString = ActiveDocument.Paragraphs(i - 1).Range
            If Length >= 55 Then
                Char = Right(ParString, 1)
                If Char = vbCr Then
                    ActiveDocument.Paragraphs(i - 1).Range = Left(ParString, Length - 1) & " "
                End If
                i = i - 1
            ElseIf Left(ActiveDocument.Paragraphs(i), 7) = "CHAPTER" Then
                ActiveDocument.Paragraphs(i).Range.Font.Bold = True
                ActiveDocument.Paragraphs(i - 1).Range.InsertBreak Type:=wdPageBreak
            End If
        Blanks = 0
        End If
        If Blanks > 10 Then Exit For
    Next
    MsgBox "Done"
End Sub
 
Thanks for the reply.

Whilst I found it a little hard to use your code, the VBA help in Word offered the sollution, eventually. :)

Here it is for anyone interested:

Code:
     Set myRange = ActiveDocument.Content
          
     With myRange.Find
       .Text = "\(*\)"
       .MatchWildcards = True
       .Replacement.Font.Size = 10
       .Execute Replace:=wdReplaceAll
     End With
 

Users who are viewing this thread

Back
Top Bottom