View Single Post
 
Old 01-16-2020, 11:58 AM
thiagoafdoria thiagoafdoria is offline Windows 10 Office 2019
Novice
 
Join Date: Feb 2017
Posts: 18
thiagoafdoria is on a distinguished road
Default Turning pieces of regular text into comments and vice-versa

Hi!

I don't know if it is possible, but I'd like to convert regular text into comments and to convert comments into regular text with macros.
My idea is to use "###" to delimitate the text that should be converted into a comment. So I could have a paragraph in the middle of which there would be the following: ###This is a comment.###, and after I run the macro I would have in a balloon: This is a comment. (The "###" gets excluded).

I already have two macros that accomplish almost the same regarding footnotes:

1. To transform text between "[!" and "!]" into footnotes, excluding those signs, "[!" and "!]" in the final result:

Code:
Sub Demo()
Application.ScreenUpdating = False
Dim Rng As Range, FtNt As Footnote
With ActiveDocument.Range
  With .Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Text = "\[\!*\!\]"
    .Replacement.Text = ""
    .Forward = True
    .Format = False
    .Wrap = wdFindStop
    .MatchWildcards = True
    .Execute
  End With
  Do While .Find.Found
    .Characters.First.Text = vbNullString
    .Characters.First.Text = vbNullString
    .Characters.Last.Text = vbNullString
    .Characters.Last.Text = vbNullString
    Set Rng = .Duplicate
    .Collapse wdCollapseStart
    Set FtNt = .Footnotes.Add(.Duplicate)
    Rng.Start = FtNt.Reference.End
    FtNt.Range.FormattedText = Rng.FormattedText
    Rng.Delete
    If .End = ActiveDocument.Range.End Then Exit Sub
    .Collapse wdCollapseEnd
    .Find.Execute
  Loop
End With
Application.ScreenUpdating = True
End Sub

2. To turn footnotes into delimited fragments between "[!" and "!]" in the body of the text:

Code:
Sub Demo()
Application.ScreenUpdating = False
Dim Rng As Range
With ActiveDocument
  Do While .Footnotes.Count > 0
    With .Footnotes(1)
      Set Rng = .Reference
      With Rng
        .Collapse wdCollapseStart
        .Text = "[!!]"
        .Start = .Start + 2
        .Collapse wdCollapseStart
      End With
      Rng.FormattedText = .Range.FormattedText
      .Delete
    End With
  Loop
End With
Application.ScreenUpdating = True
End Sub
Is it possible to adapt those macros in order to accomplish what I want regarding comments?

Thanks's!
Reply With Quote