Log in

View Full Version : word 2010 - how do I creat macro to add datetime stamp bookmark?



RokkoRokko
04-03-2018, 06:51 AM
I am trying to create a macro to create a datetime stamp and insert the bookmark for that current date-time of each unique running of the macro into it.

I create my datetime stamp graphic using 'record macro .... [using insert date time function]

and during record I go to the point where I want to insert the bookmark

I add insert date of the current time of use... eg "2018-04-04" then backstep to remove the dashes and a 't' to the beginning so I am left with "t20180404".

I then repeat the procedure to add 24hr timestamp to the above so end up with this "t201804040141"

I then go to the end of the bookmark text and backtrack select to the beginning, selecting the text...

I then "ctrl-C' to copy the text and "Ctrl-X" to cut the test [its for the bookmark only]

I then go to insert bookmark and paste the "t201804040141" [without quotes] into the bookmark and hit add.

I end the recording with cursor left in position I want after the bookmarked created graphic

I run the macro and it works fine...

but then I run it and instead of copying and pasting new current datetime stamp it pastes the datetimestamp created during the original macro recording.

so my question is....

How can I do this so the current datetime is added for each unique time time the macro is run?

thanks in advance...

gmayor
04-03-2018, 08:01 AM
Maybe


Sub DateStamp()
Dim strDate As String
strDate = Format(Date, "tyyyymmdd") & Format(Time, "hhmm")
Selection.Text = strDate
Selection.Bookmarks.Add strDate
End Sub