
Help? Get date from user and then add days to input?
Hi, Vector,
Your code works OK for me (recognizing that you've chose the date format
with days first and then month, the results I got added 2 to the first
number, which represents the days).
Another way to approach this, which gives more control over the amount of
added time, is to use the DateAdd statement, like this:
Sub InsertFutureDates()
Dim strData As Date, nDays As Integer
strData = InputBox("Enter the renewal date (dd/mm/yyyy)", "d/mm/yyyy")
nDays = Val(InputBox("Enter number of days to advance", "Add days", "2"))
strData = DateAdd(interval:="d", Number:=nDays, Date:=strData)
Selection.InsertBefore Format(strData, "d/mm/yyyy")
End Sub
--
Regards,
Jay Freedman
Microsoft Word MVP Word MVP FAQ site: http://www.mvps.org/word
Quote:
> Here's what I have so far but it doesn't work. All it does is add a
> number to the month.
> Sub InsertFutureDates()
> Dim strData As Date
> strData = InputBox("Enter the renewal date (dd/mm/yyyy)", "d/mm/yyyy")
> Selection.InsertBefore Format((strData + 2), "d/mm/yyyy")
> End Sub
> Any idea how to modify this so that it adds 2 days to the input date?
> Thanks.
> >I want to create a Word macro that pops up a dialog box asking the
> >user to input a date (ie. a start date). Then I want to fill out the
> >document with values such as that date + x days (ie. deadlines that
> >are so many days from start date).
> >How can I do this?
> >Thanks for any help.