0

I have several Word-Files containing old-style non-clickable UTF8-character checkboxes () and I want to replace them with real, clickable Checkboxes. They should be unchecked for  and checked for another specified UTF8-character (which I do not know the number of right now).

I tried search and replace and copying from macros I've found online. I'm not a word user and this is a one-time-task, so I sadly do not have the time to learn VBA well enough to write such a thing as a macro.

I've found this online, but in the Macros-Window, I cannot even copy  to "string to be searched".

For Each myStoryRange In ActiveDocument.StoryRanges
    With myStoryRange.Find
        .Text = "string to be searched"
        .Replacement.Text = "string to be replaced"
        .Wrap = wdFindContinue
        .ClearFormatting
        .Replacement.ClearFormatting
        .Replacement.Highlight = False
        .Execute Replace:=wdReplaceAll
    End With
Next myStoryRange  
Cindy Meister
  • 25,071
  • 21
  • 34
  • 43
  • You seem to be confusing Unicode with UTF-8 encoding. Please see https://www.joelonsoftware.com/2003/10/08/the-absolute-minimum-every-software-developer-absolutely-positively-must-know-about-unicode-and-character-sets-no-excuses/. – GSerg Jun 17 '19 at 13:31
  • Possible duplicate of [How to type currency symbols in Visual Basic Editor](https://stackoverflow.com/q/24384952/11683) – GSerg Jun 17 '19 at 13:35

1 Answers1

0

For Searching UTF=8 Character you have to search Unicodes like

  1. U+2610 decimal &#9744 Unchecked Checkbox
  2. U+2611 decimal &#9745 Checked Checkbox
  3. U+2612 decimal &#9746 Crossed Checkbox

Other like Unicode characters may also be explored for exactly what is it in your case. I tested with U+2610 decimal &#9744 Unchecked Checkbox.

For replacement with FormField type of ComboBox I successfully used the code below

Sub TestFormFieldCB()
Dim Rng As Range, cb As FormField
ActiveDocument.Content.Select

    With Selection.Find
        .Text = ChrW(9744)

        Do While .Execute
        Set Rng = Selection.Range
        ht = Rng.Font.SizeBi
        Rng.Delete
        Set cb = Rng.FormFields.Add(Rng, wdFieldFormCheckBox)
        cb.CheckBox.Size = ht
        Loop
    End With
'ActiveDocument.Protect wdAllowOnlyFormFields
End Sub

The disadvantage of this type ComboBox is document is to be protected for the ComboBox to be clickable.

As Second option I tried with ActiveX Type ComboBox. It is easilyclickable even in unprotected mode but difficult to align and size with the text in the line. Also Somehow i could not use the same find Loop as in the above code and had to work around with some other way.

The final tested code is

Sub testActiveXCB()
Dim Rng As Range, cb As InlineShape, Fnd As Boolean
ActiveDocument.Content.Select
    With Selection.Find
        .Text = ChrW(9744)
        .Execute


        Do While Selection.Find.Found
        Set Rng = Selection.Range
        ht = Rng.Font.SizeBi
        Rng.Delete
        Set cb = Rng.InlineShapes.AddOLEControl(ClassType:="Forms.CheckBox.1")
        Debug.Print cb.OLEFormat.Object.Name & "-" & cb.Height
        cb.Width = cb.Height
        cb.Width = ht
        cb.OLEFormat.Object.Caption = ""
        cb.OLEFormat.Object.PicturePosition = 2
        'Use next Line when replacing Checked Unicode Char mat be U+2611 or U+2612
        'cb.OLEFormat.Object.Value = True
        ActiveDocument.Content.Select
        Selection.Find.Execute
        Loop
    End With

End Sub

(All tests are carried out in Word 2007 only)

I request more answers and eager to learn from Word VBA experts regarding

  1. Why the ActiveX Combo Box could not be inserted with the simple Find loop used in case of FormField type Combo Box?
  2. How to effectively align Active X Combo Box with the text Line?
Ahmed AU
  • 2,757
  • 2
  • 6
  • 15