Word模板关联Date Picker的日期书签始终显示30 Dec 1899求助
问题:Word宏启用模板Date Picker日期异常显示为“30 Dec 1899”
我用VBA开发了多个关联的Word宏启用模板,所有模板均采用通用编程逻辑与书签配置。后续为模板新增Date Picker功能替代手动输入日期的文本框,该功能在除首个开发的模板外的所有模板中均正常生效。但首个模板中,关联Date Picker的日期书签始终显示为“30 Dec 1899”,而非用户选择的日期,即使禁用Date Picker也会出现此问题。
我已尝试ChatGPT给出的多种代码优化方案,均未解决问题,且已确认UserForm上的Date Picker已正确初始化并启用。由于微软Office以30 Dec 1899为基准日期,我推测问题出在文档格式或属性而非VBA代码,所有模板均在同一工作站和Word应用中开发,排除设备或应用设置问题。
现寻求查看Word文档详细设置、属性及格式的方法。
其他模板中生效的VBA代码
Dim Selected_Date As Range Set Selected_Date = ActiveDocument.Bookmarks("Selected_Date").Range Selected_Date.Text = Format(Me.Date_Picker.Value, "dd Mmm yy") Dim Selected_Date_1 As Range Set Selected_Date_1 = ActiveDocument.Bookmarks("Selected_Date_1").Range Selected_Date_1.Text = Format(Me.Date_Picker.Value, "Mmm yy") Dim Selected_Date_2 As Range Set Selected_Date_2 = ActiveDocument.Bookmarks("Selected_Date_2").Range Selected_Date_2.Text = Format(Me.Date_Picker.Value, "Mmm yy")
尝试过的无效代码示例
Suggestion 1
Private Sub UserForm_Click() DTPicker1.Format = dtpCustom DTPicker1.CustomFormat = "dd MM yyyy" DTPicker1.Value = Date End Sub
Suggestion 2
Private Sub CommandButtonOk_Click() Application.ScreenUpdating = False With ActiveDocument Call UpdateBookmark("CDOB", Format(TextBoxCDOB.Value, "d MMM yyyy")) End With Application.ScreenUpdating = True Unload Me End Sub
内容的提问来源于stack exchange,提问作者Grandpa_Clem
相关产品推荐
相关产品推荐

