How to assign the Value of Yesterday's Date to a String Variable in Visual Basic For Applications

Posted on 2008-11-11
Medium Priority
Last Modified: 2012-05-05
This question is related a little related to a previous question in which I had asked how to get yesterdays date typed into a word document in response to the click event of a button on a VBA form.
The answer was
Selection.TypeText Format(Now - 1, "dd MMMM YYYY")
and this did work.
I would now like to be able to assign the value of yesterday's date to a string variable and would appreciate help for that.

So that if I say
Dim YesterdayDate As String
YesterdayDate = ?
( I need help what should come in place of ? so that the String Variable YesterdayDate becomes equal to Monday, 10 November 2008 assuming that today's date is Tuesday, 11 November 2008))
Thank you for your help in anticipation.
Question by:FaheemAhmadGul
  • 3
  • 2
LVL 17

Assisted Solution

JohnGerhardt earned 400 total points
ID: 22931785
How about
Yesterday = Format(Now - 1, "dd MMMM YYYY")
LVL 13

Expert Comment

ID: 22931787
Same concept as yestrerdaysdate = Date() -1

Author Comment

ID: 22931942
Many thanks for the prompt response to my query. Both of the above solutions work. The one by JohnGerhardt shows date as 10 November 2008 and one by leegclystvale shows date as 10/11/2008.
Can any of the above solutions be modified a little so that the date also includes day of the week. So that the variable  YesterdaysDate becomes equal to Monday, 10 November 2008.

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

LVL 13

Expert Comment

ID: 22932044
yesterdaysdate = Format(Now()-1, "Long Date")
LVL 13

Accepted Solution

leegclystvale earned 600 total points
ID: 22932058
In fact ignore that, use yesterdaysdate = Format(now -1, "dddd, MMM d yyyy")

Author Closing Comment

ID: 31515575
Excellent! This worked perfectly. Many thanks. As this required some extra work and both of you contributed to the solution, I have increased the total points to 250 and split them 150+100. I hope this is OK.
Once again thanking you both. Regards Faheem

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Article by: evilrix
Looking for a way to avoid searching through large data sets for data that doesn't exist? A Bloom Filter might be what you need. This data structure is a probabilistic filter that allows you to avoid unnecessary searches when you know the data defin…
The viewer will learn how to implement Singleton Design Pattern in Java.
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
Suggested Courses

862 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