Prev: Word 2007: ContentControl's method ToggleEditPlaceholderText is mi
Next: PDF disables Word Macros
From: Word_2007_SASS on 27 Apr 2010 10:28 Hi All, We currently have a Word 2007 template in which we require two dynamic dates to appear on the cover page. The first date "Approval Date" is a typical PRINTDATE field, but the second field is a "Review Date" and needs to be equal to the PRINTDATE plus 3 years. How can we write code in vba to insert a PRINTDATE field and calculate that field to be equal to 3 years from the print date? Any help is appreciated! Thanks!
From: Graham Mayor on 27 Apr 2010 11:49 If you only want to add three full years to the field, the construction of the fields would be { PrintDate \@ "d MMM" } { ={ PrintDate \@ "yyyy" } + 3 } However if you want to use vba, you may as well intercept the print routine and add a couple of docvariable fields ( {DocVariable varPrintDate} and {DocVariable varNextPrint } ) to the places you want the two dates to appear and the following macro will update those fields when you print the document. Sub FilePrint() Dim oVars As Variables Set oVars = ActiveDocument.Variables oVars("varPrintDate").Value = "Approval Date:" & vbTab & Format(Date, "d MMM yyyy") oVars("varNextPrint").Value = "Review Date:" & vbTab & Format(Date, "d MMM ") & Format(Date, "yyyy") + 3 ActiveDocument.Fields.Update ActiveDocument.PrintOut End Sub -- <>>< ><<> ><<> <>>< ><<> <>>< <>><<> Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org <>>< ><<> ><<> <>>< ><<> <>>< <>><<> "Word_2007_SASS" <Word2007SASS(a)discussions.microsoft.com> wrote in message news:83706CDC-3AD7-4D9A-B9B5-9014A892A43C(a)microsoft.com... > Hi All, > > We currently have a Word 2007 template in which we require two dynamic > dates > to appear on the cover page. The first date "Approval Date" is a typical > PRINTDATE field, but the second field is a "Review Date" and needs to be > equal to the PRINTDATE plus 3 years. > > How can we write code in vba to insert a PRINTDATE field and calculate > that > field to be equal to 3 years from the print date? > > Any help is appreciated! > > Thanks!
From: Word_2007_SASS on 27 Apr 2010 11:50 Sorry, I should have emphasized that the Review Date MUST be a field, so that if the Approval Date updates when the document is printed, the Review Date must also update so that the dates match and the Review Date is 3 years in the future. Thanks! "Word_2007_SASS" wrote: > Hi All, > > We currently have a Word 2007 template in which we require two dynamic dates > to appear on the cover page. The first date "Approval Date" is a typical > PRINTDATE field, but the second field is a "Review Date" and needs to be > equal to the PRINTDATE plus 3 years. > > How can we write code in vba to insert a PRINTDATE field and calculate that > field to be equal to 3 years from the print date? > > Any help is appreciated! > > Thanks!
From: Graham Mayor on 28 Apr 2010 02:28 Both my suggestions use fields? In the case of the macro suggestion, this has the additional advantage of updating the field before the document is printed so you may immediately see the change in the document, by intercepting the print command and updating docvariable fields in the document. -- <>>< ><<> ><<> <>>< ><<> <>>< <>><<> Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org <>>< ><<> ><<> <>>< ><<> <>>< <>><<> "Word_2007_SASS" <Word2007SASS(a)discussions.microsoft.com> wrote in message news:904F5EA1-F812-4B98-82E5-9BB1C276B61D(a)microsoft.com... > Sorry, I should have emphasized that the Review Date MUST be a field, so > that > if the Approval Date updates when the document is printed, the Review Date > must also update so that the dates match and the Review Date is 3 years in > the future. > > Thanks! > > > "Word_2007_SASS" wrote: > >> Hi All, >> >> We currently have a Word 2007 template in which we require two dynamic >> dates >> to appear on the cover page. The first date "Approval Date" is a typical >> PRINTDATE field, but the second field is a "Review Date" and needs to be >> equal to the PRINTDATE plus 3 years. >> >> How can we write code in vba to insert a PRINTDATE field and calculate >> that >> field to be equal to 3 years from the print date? >> >> Any help is appreciated! >> >> Thanks!
From: Peter Jamieson on 28 Apr 2010 11:41 > { PrintDate \@ "d MMM" } { ={ PrintDate \@ "yyyy" } + 3 } If you want it to work on 29 Feb I think you have to do a bit more, e.g. { QUOTE "{ ={ PRINTDATE \@YYYY }+3 }{ IF { PRINTDATE \@MDD } = 229 "-02-28" "{ PRINTDATE \@-MM-DD }" } \@DD MMM YYYY } Same kind of problem for the VBA approach. Peter Jamieson http://tips.pjmsn.me.uk On 27/04/2010 16:49, Graham Mayor wrote: > If you only want to add three full years to the field, the construction of > the fields would be > > { PrintDate \@ "d MMM" } { ={ PrintDate \@ "yyyy" } + 3 } > > However if you want to use vba, you may as well intercept the print routine > and add a couple of docvariable fields ( {DocVariable varPrintDate} and > {DocVariable varNextPrint } ) to the places you want the two dates to appear > and the following macro will update those fields when you print the > document. > > > Sub FilePrint() > Dim oVars As Variables > Set oVars = ActiveDocument.Variables > oVars("varPrintDate").Value = "Approval Date:"& vbTab& Format(Date, "d MMM > yyyy") > oVars("varNextPrint").Value = "Review Date:"& vbTab& Format(Date, "d MMM > ")& Format(Date, "yyyy") + 3 > ActiveDocument.Fields.Update > ActiveDocument.PrintOut > End Sub > >
|
Next
|
Last
Pages: 1 2 Prev: Word 2007: ContentControl's method ToggleEditPlaceholderText is mi Next: PDF disables Word Macros |