Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #16  
Old 06-04-2016, 12:06 AM
macropod's Avatar
macropod macropod is offline Macro to find text and replace with form field containing that text Windows 7 64bit Macro to find text and replace with form field containing that text Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
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

I've re-tested and the code works fine. Try again, with:


Code:
Sub AddFormFields()
Dim pState As Boolean, Pwd As String, StrTmp As String, FFld As FormField
With ActiveDocument
  pState = False
  If .ProtectionType <> wdNoProtection Then
    Pwd = InputBox("Please enter the Password", "Password")
    pState = True
    .Unprotect Pwd
  End If
  With .Range
    With .Find
      .ClearFormatting
      .Text = "My Kitchen"
      .Replacement.Text = ""
      .Forward = True
      .Wrap = wdFindStop
      .Format = True
      .MatchCase = False
      .MatchWholeWord = False
      .MatchWildcards = True
      .MatchSoundsLike = False
      .MatchAllWordForms = False
      .Execute
    End With
    Do While .Find.Found
      StrTmp = .Duplicate.Text
      Set FFld = ActiveDocument.FormFields.Add(Range:=.Duplicate, _
                Type:=wdFieldFormTextInput)
      FFld.Result = StrTmp
      .Start = FFld.Range.End
      .Find.Execute
    Loop
  End With
  If pState = True Then .Protect Type:=wdAllowOnlyFormFields, Noreset:=True, _
              Password:=Pwd
  pState = False
End With
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #17  
Old 06-04-2016, 01:47 AM
edsulst edsulst is offline Macro to find text and replace with form field containing that text Windows 10 Macro to find text and replace with form field containing that text Office 2010 32bit
Novice
 
Join Date: Jun 2016
Posts: 3
edsulst is on a distinguished road
Default

Paul,

This works.
Don't know what I did wrong, but it works.

Thanks for your quick support on an old ticket.

Gr. Edwin
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro to find text in between two characters and then format selected text? qcom Word 5 02-19-2015 11:23 PM
Macro to find text and replace with form field containing that text Form Fields - Create blank form text field with if statement? LAssist2011 Word 5 12-14-2011 03:02 PM
Macro to populate a text form field based on dropdown selection koloa Word 0 10-20-2011 11:52 AM
Macro to find text and replace with form field containing that text Need help on Macro 03- Find text - if text is blank then remove line simpleonline1234 Word VBA 1 02-25-2011 02:28 AM
Treating a text box like a form Text Field jackaroo Word 0 08-18-2010 10:20 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 12:01 PM.


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