Find & Replace Each Instance

S

Steve C

I've created a text box in a userform in the VB Editor where a user inserts a
date. I'm trying to then have the code search the document for each instance
of the words "Created Date:", which appears in the first row and first cell
of a varying number of two column tables (The number of tables where "Created
Date" appears will vary, depending on another prompt in my form). Each time
"Created Date" is found in a table, I want to have the date that was input in
the form to be inserted in the cell immediately below "Created Date".

I hope I'm being clear enough. Thanks in advance for your help!
 
J

Jay Freedman

I've created a text box in a userform in the VB Editor where a user inserts a
date. I'm trying to then have the code search the document for each instance
of the words "Created Date:", which appears in the first row and first cell
of a varying number of two column tables (The number of tables where "Created
Date" appears will vary, depending on another prompt in my form). Each time
"Created Date" is found in a table, I want to have the date that was input in
the form to be inserted in the cell immediately below "Created Date".

I hope I'm being clear enough. Thanks in advance for your help!

Instead of doing a find & replace, there's a better way. In the
template for these documents, include a {DocVariable CreatedDate}
field in each place you want this value to appear. In the userform's
Click event for the OK button, include code like this (of course, you
need other code to validate the entry):

ActiveDocument.Variables("CreatedDate").Value = TextBox1.Text
ActiveDocument.Fields.Update

If you're creating tables on the fly as it sounds like you're doing,
you can put the DocVariable field in the proper cell at the time the
table is created.
 
S

Steve C

Thanks, Jay! I will give that a shot.

Steve C

Jay Freedman said:
Instead of doing a find & replace, there's a better way. In the
template for these documents, include a {DocVariable CreatedDate}
field in each place you want this value to appear. In the userform's
Click event for the OK button, include code like this (of course, you
need other code to validate the entry):

ActiveDocument.Variables("CreatedDate").Value = TextBox1.Text
ActiveDocument.Fields.Update

If you're creating tables on the fly as it sounds like you're doing,
you can put the DocVariable field in the proper cell at the time the
table is created.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top