I have a MS-Word form that contain some Date Pickers, I need to create vba that changes the dates to the next week (date+7days), can anyone help me please?
I tried this but it didn't work
Dim PODate As Date
Dim strDate As String
Dim doc As Word.Document
Dim ccs As Word.ContentControl
Set doc = ActiveDocument
Set ccs = ActiveDocument.SelectContentControlsByTag("Date1").Item(1)
strDate = ccs.Range.Text
PODate = CDate(strDate)
Selection.GoTo What:=wdGoToBookmark, Name:="Date1"
Selection.TypeText Text:=Format(PODate + 7, "mm/dd/yyyy")
End Sub
Try:
Dim strDate As String
With ActiveDocument
strDate = .SelectContentControlsByTag("Date1").Item(1).Range.Text
.Bookmarks("Date1").Range.Text = Format(DateAdd("d", 7, strDate), "mm/dd/yyyy")
End With
or even:
With ActiveDocument
.Bookmarks("Date1").Range.Text = Format(DateAdd("d", 7, .SelectContentControlsByTag("Date1").Item(1).Range.Text), "mm/dd/yyyy")
End With
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.