我有以下 VBA 代码可以在书签位置以代码格式插入日期。每次我打开文件时都会插入日期而不删除旧的书签文本,所以我在代码顶部添加了删除文本,但现在它删除了格式并插入了文本有没有办法保持格式?
Sub AutoOpen()
'
' AutoOpen Macro
'
'
ActiveDocument.Bookmarks("MyDate").Range.Delete
ActiveDocument.Bookmarks("MyDate1").Range.Delete
ActiveDocument.Bookmarks("MyDate2").Range.Delete
ActiveDocument.Bookmarks("MyDate3").Range.Delete
ActiveDocument.Bookmarks("MyDate4").Range.Delete
ActiveDocument.Bookmarks("MyDate5").Range.Delete
ActiveDocument.Bookmarks("MyDate6").Range.Delete
With ActiveDocument.Bookmarks("MyDate").Range
.InsertBefore Format(Date + 1, "dddd dd mmmm yyyy")
End With
With ActiveDocument.Bookmarks("MyDate1").Range
.InsertBefore Format(Date + 2, "dddd dd mmmm yyyy")
End With
With ActiveDocument.Bookmarks("MyDate2").Range
.InsertBefore Format(Date + 3, "dddd dd mmmm yyyy")
End With
With ActiveDocument.Bookmarks("MyDate3").Range
.InsertBefore Format(Date + 4, "dddd dd mmmm yyyy")
End With
With ActiveDocument.Bookmarks("MyDate4").Range
.InsertBefore Format(Date + 5, "dddd dd mmmm yyyy")
End With
With ActiveDocument.Bookmarks("MyDate5").Range
.InsertBefore Format(Date + 6, "dddd dd mmmm yyyy")
End With
With ActiveDocument.Bookmarks("MyDate6").Range
.InsertBefore Format(Date + 7, "dddd dd mmmm yyyy")
End With
End Sub