Consulting

Results 1 to 3 of 3

Thread: Find and Replace for wdFieldFormCheckBox with text beside it

  1. #1
    VBAX Newbie
    Joined
    Jun 2020
    Posts
    1
    Location

    Find and Replace for wdFieldFormCheckBox with text beside it

    Hello,

    Beginner here! I'm trying to use a macro in Word to find a Legacy checkbox (wdFieldFormCheckBox) with particular text beside it, in order to delete both the checkbox and the text. I was using the following to find text and replace it with nothing, but I don't know how to include the checkbox in the "Find" function. Thanks for your help in advance!

    Sub Test()
    
    
    With Selection.Find
    
    
    .ClearFormatting
    
    
    .Replacement.ClearFormatting
    
    
    .Text = "Protocol"
    
    
    .Replacement.Text = ""
    
    
    .Forward = True
    
    
    .Wrap = wdFindContinue
    
    
    .Format = False
    
    
    .MatchCase = True
    
    
    .MatchWholeWord = False
    
    
    .MatchWildcards = False
    
    
    .MatchSoundsLike = False
    
    
    .MatchAllWordForms = False
    
    
    .Execute Replace:=wdReplaceAll
    
    
    End With

  2. #2
    Assuming the check box and text are alone in a paragraph then with the form unprotected:

    Sub Macro1()
    Dim oFF As FormField
    Dim orng As Range
        For Each oFF In ActiveDocument.FormFields
            If oFF.Type = wdFieldFormCheckBox Then
                Set orng = oFF.Range.Paragraphs(1).Range
                'orng.Select
                If InStr(1, orng.Text, "Protocol") > 0 Then
                    orng.Text = ""
                End If
            End If
        Next oFF
        Set oFF = Nothing
        Set orng = Nothing
    End Sub
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  3. #3
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,121
    Location
    Cross-posted at: https://stackoverflow.com/questions/...ckbox-and-text
    Please read VBA Express' policy on Cross-Posting in Rule 3: http://www.vbaexpress.com/forum/faq...._new_faq_item3
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

Tags for this Thread

Posting Permissions

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