![]() |
|
|
|
#1
|
|||
|
|||
|
I will have a document with Vol. 19, No. 1, January 2019 in the header.. How can I get the No. and Date to change every time I run a macro?
That is, the first doc is... Vol. 19, No. 1, January 2019 and the next Vol. 19, No. 2, January 2019 and the next Vol. 19, No. 3, January 2019 etc... I would like the to increment by 1 every time the macro is run and the date to change based on the current date. |
|
#2
|
||||
|
||||
|
I would be using a content control linked to a built-in document property for the Number, and a SaveDate field for the date.
To add the content control, put your cursor in the header and type in "No. " and then go to Insert > Quick Parts > Document Property > Category. To add the SaveDate field, put your cursor in the header and go to Insert > Quick Parts > Field > SaveDate (and chose the relevant Date Format), click OK The final part is to add a macro which can update the Category property and save the file to adjust the date. Code:
Option Explicit
Sub IncrementNumber()
Dim i As Integer
i = Val(ActiveDocument.BuiltInDocumentProperties("Category").Value) + 1
ActiveDocument.BuiltInDocumentProperties("Category").Value = i
ActiveDocument.Save
UpdateAllFields
End Sub
Sub UpdateAllFields()
Dim oStory As Range
For Each oStory In ActiveDocument.StoryRanges
oStory.Fields.Update
If oStory.StoryType <> wdMainTextStory Then
While Not (oStory.NextStoryRange Is Nothing)
Set oStory = oStory.NextStoryRange
oStory.Fields.Update
Wend
End If
Next oStory
Set oStory = Nothing
End Sub
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
|
#3
|
|||
|
|||
|
That is Perfect. Thank you Andrew.
|
|
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Date stamp in Contact Notes Field | nickcwpg | Outlook | 3 | 02-20-2019 11:21 AM |
Date & time stamp problems in Word XP
|
Scotfan | Word | 3 | 03-09-2016 09:45 AM |
Word signatures w/ date stamp
|
TechieHell | Word | 2 | 03-16-2015 07:24 AM |
Issue with date format in mail merge document
|
walshjod | Mail Merge | 4 | 11-28-2012 04:46 AM |
| Outlook 2003-formatting vba Date stamp | Royzer | Outlook | 0 | 03-29-2012 10:39 AM |