Prev: Word 2007: ContentControl's method ToggleEditPlaceholderText is mi
Next: PDF disables Word Macros
From: Graham Mayor on 29 Apr 2010 01:32 Good thinking - the modified code for the macro version could be Sub FilePrint() Dim oVars As Variables Set oVars = ActiveDocument.Variables oVars("varPrintDate").Value = "Approval Date:" & vbTab & _ Format(Date, "d MMM yyyy") If Month(DateSerial(Format(Date, "yyyy"), 2, 29)) = 2 And _ Day(Date) = 29 Then oVars("varNextPrint").Value = "Review Date:" & vbTab & _ "1 Mar " & Format(Date, "yyyy") + 3 Else oVars("varNextPrint").Value = "Review Date:" & vbTab & _ Format(Date, "d MMM ") & Format(Date, "yyyy") + 3 End If ActiveDocument.Fields.Update ActiveDocument.PrintOut End SubEnd Sub which will set the Review Date to the 1st March on the 29th Deb of a leap year. -- <>>< ><<> ><<> <>>< ><<> <>>< <>><<> Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org <>>< ><<> ><<> <>>< ><<> <>>< <>><<> "Peter Jamieson" <pjj(a)KillMAPSpjjnet.demon.co.uk> wrote in message news:OY%23VXlu5KHA.3804(a)TK2MSFTNGP05.phx.gbl... > > { 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 >> >>
From: Word_2007_SASS on 29 Apr 2010 08:51 Perfect! Thanks for all the help :) "Graham Mayor" wrote: > Good thinking - the modified code for the macro version could be > > Sub FilePrint() > Dim oVars As Variables > Set oVars = ActiveDocument.Variables > oVars("varPrintDate").Value = "Approval Date:" & vbTab & _ > Format(Date, "d MMM yyyy") > If Month(DateSerial(Format(Date, "yyyy"), 2, 29)) = 2 And _ > Day(Date) = 29 Then > oVars("varNextPrint").Value = "Review Date:" & vbTab & _ > "1 Mar " & Format(Date, "yyyy") + 3 > Else > oVars("varNextPrint").Value = "Review Date:" & vbTab & _ > Format(Date, "d MMM ") & Format(Date, "yyyy") + 3 > End If > ActiveDocument.Fields.Update > ActiveDocument.PrintOut > End SubEnd Sub > > which will set the Review Date to the 1st March on the 29th Deb of a leap > year. > > -- > <>>< ><<> ><<> <>>< ><<> <>>< <>><<> > Graham Mayor - Word MVP > > My web site www.gmayor.com > Word MVP web site http://word.mvps.org > <>>< ><<> ><<> <>>< ><<> <>>< <>><<> > > > > "Peter Jamieson" <pjj(a)KillMAPSpjjnet.demon.co.uk> wrote in message > news:OY%23VXlu5KHA.3804(a)TK2MSFTNGP05.phx.gbl... > > > { 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 > >> > >> > > > . >
From: macropod on 1 May 2010 05:31 Hi, To see how to do this and just about everything else you might want to do with dates in Word, check out my Microsoft Word Date Calculation Tutorial, at: http://lounge.windowssecrets.com/index.php?showtopic=249902 or http://www.gmayor.com/downloads.htm#Third_party In particular, look at the item titled 'Calculate a day, date, month and year, using n years delay'. You'll need to change the field's DATE variables to PRINTDATE. If you want the ability to interactively calculate the date, see also 'Interactively Calculate A Past Or Future Date'. Do read the document's introductory material. -- Cheers macropod [Microsoft MVP - Word] "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!
First
|
Prev
|
Pages: 1 2 Prev: Word 2007: ContentControl's method ToggleEditPlaceholderText is mi Next: PDF disables Word Macros |