Flag text in document for VBA to find and replace RRS feed

  • Question

  • Is it possible to insert a marker of some kind in a word document, and then have VBA find the marker and replace the associated text?

    I have mailmerge template where I want the date to be fixed, so the date doesn't update when the new document is opened. All that advice I've tried doesn't work. So I came up with the idea of just putting a 'marker' in the template where the date should go. Then in my mailmerge vba code I replace the marker with the date. 

    Any thoughts, alternate ideas, etc?


    Thursday, June 2, 2016 5:13 PM


All replies

  • Oh wait, I just had a stroke of genius! Or maybe it was just a stroke. hehe Anyway..I realized that since my mailmerge fields depend on a sql query, I can just include the system date in the query. Then create a mailmerge field for that date. NOW..will it stay the same. That's the big challenge. So if today is June 2nd, 2016 then the documents created by my mailmerge process should always say June 2nd, 2016 any day that I open them.

    Please reply if you have additional suggestions.


    Thursday, June 2, 2016 5:38 PM
  • As you have already been advised in your other post, this can all be done with field coding - you do not need any VBA code or data in the data source for it.

    Paul Edstein
    [MS MVP - Word]

    Thursday, June 2, 2016 9:37 PM
  • I solved the problem by having my query supply the system date and creating a mailmerge field to accept the date. 
    Monday, June 6, 2016 4:25 PM
  • Hi todtown,

    its good to hear from you that you have solved your issue by yourself and you also share the solution with our community so that if some other member have same issue like you also can solution by your post.



    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, June 7, 2016 3:21 AM