View Single Post
 
Old 06-21-2021, 12:43 AM
Shelley Lou Shelley Lou is offline Windows 10 Office 2016
Expert
 
Join Date: Dec 2020
Posts: 259
Shelley Lou is on a distinguished road
Default VBA code help: replacing punctuation

Hi Macropod, many thanks for updating this code for me, very much appreciated. There appears to be 2 message boxes that come up and it won't let me run the macro - MsgBox Chr(34) & .Text & Char(34), how can I amend these so I don't get the message box. Thanks.

Image.JPG


Code:
'Remove punctuation and insert semi-colon at end of sentence
    .Find.Text = "[! ^13]@[!.\!\?:;]^13"
    Do While .Find.Execute = True
      With .Duplicate
        MsgBox Chr(34) & .Text & Chr(34)
        Select Case Trim(.Words.First)
          Case "and", "but", "or", "then"
            'do nothing
          Case Else
          .Words.First.InsertAfter ";"
        End Select
      End With
      .Collapse wdCollapseEnd
    Loop
  End With
  'Remove placeholder.
  .Paragraphs(1).Range.Delete
  With .Range
    'Prefix designated bold first words with a tab
    .Find.Text = "^13[A-Za-z]"
    Do While .Find.Execute = True
        MsgBox Chr(34) & .Text & Chr(34)
      With .Duplicate.Paragraphs.Last.Range
        If .Style = "Normal" Then
          If .Characters.First.Font.Bold = False Then .InsertBefore vbTab
        End If
      End With
      .Collapse wdCollapseEnd
    Loop
  End With
Reply With Quote