[英]Use vba Change the dates in MS-Word ContentControl DatePicker
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?我有一个包含一些日期选择器的 MS-Word 表单,我需要创建将日期更改为下周(日期 + 7 天)的 vba,有人可以帮我吗?
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.