• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 493
  • Last Modified:

Macro to Enter Not Current Date but Yesterday's Date in the Word Document

I need help writing a macro (or code for the click event of a button on a form) , running which will enter not the current date but the Yesterday's date.
For example if I click on this button today (assuming that the current date is 06 November 2008)  then it will type yesterday's date in the following format
05 November 2008.
I would also appreciate help for the code that will enter the day before Yesterday's date in the currently active word document. So if the current date is 06 November, when run this macro will enter the following:
04 November 2008
Thank you for your help in anticipation
0
FaheemAhmadGul
Asked:
FaheemAhmadGul
  • 2
  • 2
1 Solution
 
game-masterCommented:

good morning!

i hope this will give u idea..
i tried this and it works fine with me..


Sub typeYesterdayDate()
   
    ActiveDocument.Select
    Selection.TypeParagraph 'enter
    Selection.TypeText Format(Now - 1, "dd MMMM YYYY")

End Sub

Sub typeDayBeforeYesterday()
    ActiveDocument.Select
    Selection.TypeParagraph 'enter
    Selection.TypeText Format(Now - 2, "dd MMMM YYYY")
End Sub



game-master
0
 
FaheemAhmadGulAuthor Commented:
Many thanks. Worked perfectly. I am extremely grateful. Regards - Faheem
0
 
FaheemAhmadGulAuthor Commented:
Many thanks. Worked perfectly. I am extremely grateful.
0
 
game-masterCommented:

im glad i could help..:-)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now