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

Posted on 2008-11-06
Last Modified: 2012-05-05
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
Question by:FaheemAhmadGul
    LVL 13

    Accepted Solution


    good morning!

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

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

    End Sub

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


    Author Closing Comment

    Many thanks. Worked perfectly. I am extremely grateful. Regards - Faheem

    Author Comment

    Many thanks. Worked perfectly. I am extremely grateful.
    LVL 13

    Expert Comment


    im glad i could help..:-)

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Training Course: Java/J2EE and SOA

    This course will cover both core and advanced Java concepts like Database connectivity, Threads, Exception Handling, Collections, JSP, Servlets, XMLHandling, and more. You'll also learn various Java frameworks like Hibernate and Spring.

    If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
    Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
    Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
    This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now