Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Word07 Macro to Insert Locked Date 1

Status
Not open for further replies.
Jun 5, 2002
417
AU
Hi,

I have the following code which I want to use to create a locked date in a Word Document, but seem unable to get the syntax or code correct!

If I remember correctly Locking a Date originally seemed to me to be one of the Field options displayed when you specified "Date", but it does not seem to be there now!

Sub InsertNumDate()
'
' InsertNumDate Macro
' Inserts Numeric Date Locked! - "\!" Not at present!!
'
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:= _
"DATE ", PreserveFormatting:=True

' Selection.Fields.Locked = True 'To lock date in field - not in Word 07!

End Sub

Any help appreciated.

Peter Moran
 
[tt]Fields.Locked[/tt] is in Word 2007. The problem appears to be that you are using the [tt]Selection[/tt], and don't have the field selected.

Enjoy,
Tony

------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.

I'm working (slowly) on my own website
 
What about this ?
Code:
Dim F As Field
Set F = Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:= _ 
  "DATE ", PreserveFormatting:=True 
F.Locked = True

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks Tony and PHV,

Tony, I do not know and could not find the syntax in that context to have the Field Selected!

I thought PHV had the solution until I entered it and found the "Range" after "Add" was highlighted with the error "Unexpected end of statement"!

Any chance of an update.

Peter Moran
 
Sorry fot the typo:
Set F = Selection.Fields.Add[!]([/!]Range:=Selection.Range, Type:=wdFieldEmpty, Text:= _
"DATE ", PreserveFormatting:=True[!])[/!]

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Generally it is better to avoid the [tt]Selection[/tt], and a simpler (and faster) way would be ...

[tt][blue]Selection.Fields.Add(Range:=Selection.Range, Type:=wdFieldDate, _
PreserveFormatting:=True).Locked=True[/blue][/tt]

(I hate the way the macro recorder creates and fills an empty field!)

Enjoy,
Tony

------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.

I'm working (slowly) on my own website
 
If you're wanting to insert the current date as a fixed date, why are you messing around with fields? You could use probably nothing more complicated than:

Selection.TypeText Date

Cheers
Paul Edstein
[MS MVP - Word]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top