简体   繁体   中英

How can I insert a date that does not update, without the time, into MS Word?

I need to record the date on which I have accessed a (many) URL(s) for citation purposes. I want to create a line in my Word doc that says "Accessed:" with the CreateDate field appended. I do NOT want the time to appear. I am using this code-

 Selection.TypeText Text:=" Accessed: "

Set myField = ActiveDocument.Fields.Add(Range:=Selection.Range, _
 Type:=wdFieldCreateDate)

It works, but I don't know how to stop the CreateDate from adding the time. I have to use CreateDate because the Date field updates every time I open the file. I have tried turning off "automatic update" in Word/Options, it doesn't work. Tried to change the default CreateDate code in the Fields/Options window, it reverts back for every new usage. I've tried a bunch of different ways, found online, to add format instructions in the macro above but none of them will run. All I want is one line that says "Accessed: yyyy-mm-dd". Can someone help? Thanks.

A CREATEDATE field will not tell you when a url was accessed; it can only tell you when a document was created or last saved via Save As. Provided you understand that:

With Selection
  .Text = " Accessed: "
  .Collapse wdCollapseEnd
  .Fields.Add Range:=.Range, Type:=wdFieldEmpty, Text:="CreateDate \@ ""D MMM YYYY""", PreserveFormatting:=False
End With

Change the D MMM YYYY switch to suit your requirements.

The correct way to insert the current date as a fixed string is:

Selection.Text = " Accessed: " & Format(Now(), "D MMM YYYY")

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM