View Single Post
 
Old 03-31-2015, 08:46 AM
caboy caboy is offline Windows 7 32bit Office 2010 32bit
Novice
 
Join Date: Mar 2015
Posts: 2
caboy is on a distinguished road
Default Macro to Insert text into the beginning on specific paragraphs unless the paragraph is blank

I'm trying to insert text at the beginning of every paragraph that has a specific style format unless that paragraph is blank or begins with a space. If the paragraph is blank or contains a space I would like to macro to do nothing and move onto the next paragraph. here is what I have so far:

Code:
Sub PortionMarking()
    With ActiveDocument.Content.Find
        .ClearFormatting
        .Style = wdStyleBodyText
        Do While .Execute(Forward:=True, Format:=True) = True
                With .Parent
                    If .End = ActiveDocument.Content.End Then
                        .StartOf unit:=wdParagraph, Extend:=wdMove
                        .InsertAfter "(U) "
                        Exit Do
                    Else
                        .StartOf unit:=wdParagraph, Extend:=wdMove
                        .InsertAfter "(U) "
                        .Move unit:=wdParagraph, Count:=1
                    End If
                End With
        Loop
    End With
End Sub

Now I believe it needs another nested if statement within the do loop to check for a space or blank before deciding to insert text but I am not sure the best way to go about doing that. any help would be greatly appreciated
Reply With Quote