如何在Word中使用VBA清除日期选择器?

时间:2018-11-09 10:03:42

标签: vba ms-word

我正在尝试编写一些代码来清除模板。我尝试清除日期选择器时遇到问题。我现在拥有的代码确实清除了日期选择器,但同时也删除了日期选择器功能。代码包含在下面,在此先谢谢您!

Dim StopDate As ContentControl
Dim StartDate As ContentControl

With ActiveDocument.ContentControls(1)
  .Type = wdContentControlText
  .Range.Text = ""
  .Type = wdContentControlDropdownList
End With

With ActiveDocument.ContentControls(2)
  .Type = wdContentControlText
  .Range.Text = ""
  .Type = wdContentControlDropdownList
End With

1 个答案:

答案 0 :(得分:1)

由于您正在使用Date内容控件,因此应该使用wdContentControlDate。例如:

With ActiveDocument
  With .ContentControls(1)
    .Type = wdContentControlText
    .Range.Text = ""
    .Type = wdContentControlDate
  End With

  With .ContentControls(2)
    .Type = wdContentControlText
    .Range.Text = ""
    .Type = wdContentControlDate
  End With
End With