I am trying to create a Word document with a very simple macro of words. The macro searches for the bookmark that I placed in the text, and then adds a date of 2 weeks in the future at this place.
But when I create a new document from the template, I still do not get the bookmark. I went through this many times, and sometimes there is a bookmark there, sometimes it is there, but it does not allow you to click Go.
How can I make it work? I added a small piece of code to the Document_New() event, but it saves the message "Bookmark not found."
I have a document in a rar file, since my web server cannot handle .dotm extensions. Document
How can I make sure that when creating a new document from this template, the new document has a date two weeks ahead, located between the two bold sections?
Sub Two_Weeks_Ahead() ''# Two_Weeks_Ahead Makro Selection.GoTo What:=wdGoToBookmark, Name:="TwoWeeks" With ActiveDocument.Bookmarks .DefaultSorting = wdSortByName .ShowHidden = False End With Dim dt As Date dt = DateAdd("d", 14, DateTime.Now) Selection.TypeText Text:=Format(dt, "yyyy-MM-dd") End Sub Private Sub Document_New() Selection.GoTo What:=wdGoToBookmark, Name:="TwoWeeks" With ActiveDocument.Bookmarks .DefaultSorting = wdSortByName .ShowHidden = False End With Dim dt As Date dt = DateAdd("d", 14, DateTime.Now) Selection.TypeText Text:=Format(dt, "yyyy-MM-dd") End Sub
ms-word word-vba word-2007
Patrick
source share