View Single Post
 
Old 01-05-2014, 01:46 AM
Sandy27 Sandy27 is offline Windows 7 64bit Office 2010 64bit
Novice
 
Join Date: Nov 2013
Posts: 8
Sandy27 is on a distinguished road
Default Loop through Word doc to find and reformat text

I have created a Word file containing letters from an Access database. The font for the whole file is Times New Roman and fontsize 12. I send a copy of each letter to the subject and, at the end of each letter, there is a line that starts with “cc “ and is then followed by the name and address of the subject.

I have been trying to go through the document searching for “cc “, selecting the sentence and then changing the fontsize to 9, but I am struggling with the Word VBA. This is what I have so far:
Code:
With objWord.Visible = True 
    objDocs("Temporary.docx").Activate 
    .Selection.HomeKey unit:=wdStory 
    Do 
        With .Selection.Find 
            .Execute findtext:="cc " 
            .Wrap = wdFindStop 
            Selection.Extend 
            Selection.Extend 
            Selection.Extend 
            .ClearFormatting 
            .Font.Name = "Times New Roman" 
            .Font.Size = 12 
            .Text = "" 
            With .Replacement 
                .ClearFormatting 
                .Font.Size = 9 
                .Text = "" 
                .Collapse Direction:=wdCollapseEnd 
            End With 
        End With 
    Loop Until .Selection.Find.Found = False 
End With
I know my syntax is faulty, but am I using the right search term? Any help greatly appreciated.

Last edited by macropod; 01-05-2014 at 03:18 PM. Reason: Added code tags & formatting
Reply With Quote