Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 12-17-2018, 04:44 PM
jeffreybrown jeffreybrown is offline Stamp a document with new Vol#, Issue#, and date Windows Vista Stamp a document with new Vol#, Issue#, and date Office 2007
Expert
Stamp a document with new Vol#, Issue#, and date
 
Join Date: Apr 2016
Posts: 673
jeffreybrown has a spectacular aura aboutjeffreybrown has a spectacular aura about
Default Stamp a document with new Vol#, Issue#, and date

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.
Reply With Quote
  #2  
Old 12-17-2018, 06:14 PM
Guessed's Avatar
Guessed Guessed is offline Stamp a document with new Vol#, Issue#, and date Windows 10 Stamp a document with new Vol#, Issue#, and date Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,932
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

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
Reply With Quote
  #3  
Old 12-17-2018, 06:21 PM
jeffreybrown jeffreybrown is offline Stamp a document with new Vol#, Issue#, and date Windows Vista Stamp a document with new Vol#, Issue#, and date Office 2007
Expert
Stamp a document with new Vol#, Issue#, and date
 
Join Date: Apr 2016
Posts: 673
jeffreybrown has a spectacular aura aboutjeffreybrown has a spectacular aura about
Default

That is Perfect. Thank you Andrew.
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Date stamp in Contact Notes Field nickcwpg Outlook 3 02-20-2019 11:21 AM
Stamp a document with new Vol#, Issue#, and date Date & time stamp problems in Word XP Scotfan Word 3 03-09-2016 09:45 AM
Stamp a document with new Vol#, Issue#, and date Word signatures w/ date stamp TechieHell Word 2 03-16-2015 07:24 AM
Stamp a document with new Vol#, Issue#, and date 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

Other Forums: Access Forums

All times are GMT -7. The time now is 09:10 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft