PDA

View Full Version : Solved: Adding two month to the current date.



Birch81
09-22-2010, 03:45 AM
Hello,

I have the following VBA code

appDoc.Bookmarks("Date").range.Text = Date

How do I add two month to this date?

Bob Phillips
09-22-2010, 03:47 AM
appDoc.Bookmarks("Date").range.Text = dateserial(year(date),month(date)+2,day(date))

Birch81
09-22-2010, 04:00 AM
Hey xld,

Thank you very much. I apriciate the help you are giving.

macropod
09-22-2010, 05:36 AM
A more reliable way is:
Sub UpdateDate()
Dim intBmkLength As Integer, rngTemp As Range, BmkNm As String
BmkNm = "Date"
With appDoc
If .Bookmarks.Exists(BmkNm) Then
Set rngTemp = .Bookmarks(BmkNm).Range
rngTemp.Text = DateAdd("m", 2, Date)
.Bookmarks.Add BmkNm, rngTemp
Else
MsgBox "Bookmark " & BmkNm & " not found."
End If
Set rngTemp = Nothing
End With
End SubWith this code, the bookmark is preserved and, if the starting day exceeds the number of days in the target month, the end date is shifted forward to the last day of the target month.