Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 03-14-2014, 07:02 AM
Ulodesk Ulodesk is offline Replacing underscores with checkboxes Windows 7 64bit Replacing underscores with checkboxes Office 2013
Word 2013 Expert Cert
Replacing underscores with checkboxes
 
Join Date: Sep 2009
Location: Virginia
Posts: 866
Ulodesk is on a distinguished road
Default Replacing underscores with checkboxes

My purpose is simply to replace each series of underscores in a would-be form document (between 3 and 6, for instance; I tried with 4 here) with a legacy checkbox. I have recorded two macros but don't know how to insert the relevant part of the first (inserting a checkbox) into the second.



In the code below, the replacement line with the $ is undoubtedly extraneous; I was trying to see the macro language in case it would help me in substituting the checkbox for the $.

Code:
Sub Box()
'
' Box Macro
'
'
    Selection.FormFields.Add Range:=Selection.Range, Type:=wdFieldFormCheckBox
    Selection.TypeText Text:=" "
End Sub

Sub BoxA()
'
' BoxA Macro
'
'
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
        .Text = "____"
        .Replacement.Text = "$"
        .Forward = True
        .Wrap = wdFindContinue
        
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
End Sub
Thanks in advance.
Reply With Quote
  #2  
Old 03-14-2014, 11:08 AM
macropod's Avatar
macropod macropod is offline Replacing underscores with checkboxes Windows 7 32bit Replacing underscores with checkboxes Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Try:
Code:
Sub AddChkBox()
With ActiveDocument
  .FormFields.Add Range:=.Range.Characters.Last, Type:=wdFieldFormCheckBox
  .Characters.Last.Previous.Cut
  With .Content.Find
    .ClearFormatting
    .Text = "[_]{1,}"
    With .Replacement
      .ClearFormatting
      .Text = "^c"
    End With
    .Format = False
    .Forward = True
    .Wrap = wdFindContinue
    .MatchWildcards = True
    .Execute Replace:=wdReplaceAll
  End With
End With
End Sub
Depending on your regional settings, you may need to change '1,' to '1;'.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 03-14-2014, 11:31 AM
Ulodesk Ulodesk is offline Replacing underscores with checkboxes Windows 7 64bit Replacing underscores with checkboxes Office 2013
Word 2013 Expert Cert
Replacing underscores with checkboxes
 
Join Date: Sep 2009
Location: Virginia
Posts: 866
Ulodesk is on a distinguished road
Default Thank you

If I discern correctly, you inserted the checkbox, cut it to the clipboard, launched Find for "at least one" underscore, replaced these with the clipboard contents, and then replaced all. Looks like a great model for any such operation. Much appreciated.

Ulodesk
Reply With Quote
  #4  
Old 03-14-2014, 11:43 AM
macropod's Avatar
macropod macropod is offline Replacing underscores with checkboxes Windows 7 32bit Replacing underscores with checkboxes Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Quote:
Originally Posted by Ulodesk View Post
If I discern correctly, you inserted the checkbox, cut it to the clipboard, launched Find for "at least one" underscore, replaced these with the clipboard contents, and then replaced all.
Precisely!
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply

Tags
checkbox, form field



Similar Threads
Thread Thread Starter Forum Replies Last Post
Replacing underscores with checkboxes Find & Replace: substitute red-coloured words with underscores tinfanide Word 2 10-06-2012 11:04 PM
Replacing underscores with checkboxes checkboxes smohap Word 1 06-19-2011 09:24 PM
Replacing underscores with checkboxes Excel Checkboxes theresamille699 Excel 3 04-12-2011 08:08 PM
Ticking Checkboxes screid Word 1 06-08-2010 02:04 AM
Manipulating checkboxes in XML Ivo Word 0 12-06-2005 09:04 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 05:13 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft