Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / February 2007

Tip: Looking for answers? Try searching our database.

My form is not working in a Word Template, but it does in a normal

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Dan - 22 Feb 2007 02:51 GMT
I made a word document that shows a custom form when it is opened.  In that
form I add some data to fields (name, address...etc).  Once I click the
submit button a function replaces some text fields on the document with my
user data.

ie.  [First Name] gets replaced with Dan...etc

it works fine in the word document, but when I save the document as a
Template and try it doesnt replace the text.  It shows the form, but when I
click submit it doesnt replace the text.  Here is a part of the text replace
function.  This is my first Word macro can someone give me a hand?\

   With ThisDocument.Content.Find
       .Text = "[First Name]"
       .Replacement.Text = txtFirstName.Text
       .Format = False
       .MatchCase = True
       .MatchWholeWord = True
       .MatchSoundsLike = False
       .Execute Replace:=wdReplaceAll
   End With
Rob - 22 Feb 2007 14:45 GMT
Are you opening a new document from the template? And the code executes but
doesn't work? Not sure but you might not want to use ThisDocument. Try
ActiveDocument or something like this and see if it works.

   With Selection.Find
       .Text = "[First Name]"
       .Replacement.Text = txtFirstName.Text
       .Forward = True
       .Wrap = wdFindContinue
   End With
   Selection.Find.Execute Replace:=wdReplaceAll

I'm not sure why you're matching whole word and not sure if that is part of
the problem since mathing whole word isn't an option in the normal replace
dialog if there are non-alpha caharcters in the string.
Dan - 23 Feb 2007 01:29 GMT
I was opening it from the Template and it wasnt working.  I tried the
Selection.Find (I think I had tried it last night , but it didnt work) and it
didnt work, but ActiveDocument.Content.Find worked... Thanks!

For anyone who comes across this later on, this is what worked for me.

With ActiveDocument.Content.Find
.Text = "[First Name]"
.Replacement.Text = txtFirstName.Text
.Format = False
.MatchCase = True
.MatchWholeWord = True
.MatchSoundsLike = False
.Execute Replace:=wdReplaceAll
End With
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.