Results 1 to 4 of 4
  1. #1
    New Lounger
    Join Date
    Jan 2007
    Location
    Denmark
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I am making a macro that tags all the styles in a document so that I can strip the formatting by putting it through Note Pad. In the second macro, I convert the stripped text to the original formatting and delete the tags. My main font is Arial. So far so good.

    In the documents, there are mathematical symbols, such as arrows. I find them in the “Symbols” font.

    I need to turn the symbols into text, e.g. <right_arrow>, because when they are put through Note Pad, the symbol is lost. That works fine in the first macro with this:

    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
    .Text = ChrW(61611)
    .Replacement.Text = "<arrow_double>"
    .Forward = True
    .Wrap = wdFindContinue
    End With
    Selection.Find.Execute
    With Selection
    If .Find.Forward = True Then
    .Collapse Direction:=wdCollapseStart
    Else
    .Collapse Direction:=wdCollapseEnd
    End If
    .Find.Execute Replace:=wdReplaceOne
    If .Find.Forward = True Then
    .Collapse Direction:=wdCollapseEnd
    Else
    .Collapse Direction:=wdCollapseStart
    End If
    .Find.Execute
    End With
    Selection.Find.Execute Replace:=wdReplaceAll

    The macro recorder did that for me. But it will not work in reverse, i.e. turning the tag back into the symbol. I’ve worked out this macro which works individually on each instance.

    ‘2192 Rightwards Arrow
    Selection.Find.ClearFormatting
    With Selection.Find
    .Text = "<arrow_right>"
    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindContinue
    .Format = False
    End With
    Selection.Find.Execute
    Selection.TypeText Text:="2190"
    Selection.ToggleCharacterCode

    Can I turn this into a loop? There must be a better way to do it than the above. I have trouble figuring out the unicode aspects of this.

    Thanks for your help.

    Cheers, Bill

  2. #2
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,054
    Thanks
    2
    Thanked 417 Times in 346 Posts
    Hi Bill,

    Your two macros could be reduced to:
    Code:
    Sub To_arrow_double()
    With ActiveDocument.Content.Find
      .ClearFormatting
      .Replacement.ClearFormatting
      .Text = ChrW(61611)
      .Replacement.Text = "<arrow_double>"
      .Forward = True
      .Wrap = wdFindContinue
      .Execute Replace:=wdReplaceAll
    End With
    End Sub
    
    Sub Arrow_Double_To_ChrW_2190()
    With Activedocument.Content.Find
      .ClearFormatting
      .Replacement.ClearFormatting
      .Text = "<arrow_double>"
      .Replacement.Text = ChrW(2190)
      .Replacement.Font.Name = "WingDings 3"
      .Forward = True
      .Wrap = wdFindContinue
      .Execute Replace:=wdReplaceAll
    End With
    End Sub
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  3. #3
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts
    Coincidentally, I'd just posted another solution in the Word Processing forum, where the question had already been posted on 1/24/2010. Am reproducing that solution here, and will lock the thread in the Word Processing forum.

    The gist of this approach is that it finds each instance, stops there, and does the 'replace' by re-inserting the symbol.

    Code:
    Sub RestoreArrowDouble()
       Selection.HomeKey Unit:=wdStory
       With Selection.Find
          .Text = "<arrow_double>"
          .Forward = True
          .Wrap = wdFindStop
          Do Until .Execute = False
             Selection.InsertSymbol Font:="Symbol", _
                CharacterNumber:=-3925, Unicode:=True
          Loop
       End With
    End Sub
    Gary

  4. #4
    New Lounger
    Join Date
    Jan 2007
    Location
    Denmark
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hey Gary and Macropod,

    Thanks for the help. Does anybody know where I can find an explanation of Unicode in VBA?

    Cheers, Bill

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •