View Full Version : [SOLVED:] Remove fullstop from headline
Programmer_n
04-16-2016, 05:59 AM
Is there a macro to remove full stop from the headline (Headline level 1 and headline level 2).
Programmer_n
04-16-2016, 06:27 AM
Sub Heading_punctuation_remove()
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
        .Text = "([.])"
        .Replacement.Text = ""
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchWildcards = True
        .Style = ActiveDocument.Styles("Heading 1")
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
End Sub
Paul_Hossler
04-16-2016, 11:57 AM
I think that will find any periods in the heading (e.g. $123.45)
If you only want the trailing period, this might work better
   With ActiveDocument.Content.Find
        .ClearFormatting
        .Style = ActiveDocument.Styles("Heading 1")
        .Replacement.ClearFormatting
        .Text = ".^0013"
        .Replacement.Text = "^p"
        .Forward = True
        .Wrap = wdFindContinue
        .Format = True
        .MatchCase = False
        .MatchWholeWord = False
        .MatchAllWordForms = False
        .MatchSoundsLike = False
        .MatchWildcards = True
        .Execute Replace:=wdReplaceAll
    End With
Programmer_n
04-16-2016, 06:00 PM
Paul,
Thanks. Slightly re-modified .Text to check for question marks and exclamation marks  .Text = "([.\?\!])". It still works in your code when I replace . with ? or ! at an instance.
How to group the three things within .text in your code?
gmaxey
04-17-2016, 05:28 AM
I looks like you still have a question here:
Sub ScratchMacro()
With ActiveDocument.Content.Find
    .ClearFormatting
    .Style = ActiveDocument.Styles("Heading 1")
    .Replacement.ClearFormatting
    .Text = "[.\?\!]" & Chr(13)
    .Replacement.Text = "^p"
    .Forward = True
    .Wrap = wdFindContinue
    .Format = True
    .MatchCase = False
    .MatchWholeWord = False
    .MatchAllWordForms = False
    .MatchSoundsLike = False
    .MatchWildcards = True
    .Execute Replace:=wdReplaceAll
End With
lbl_Exit:
  Exit Sub
End Sub
Programmer_n
04-17-2016, 05:38 AM
Thanks gmaxey.
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.