How to insert a field in a table cell

P

Peter

I use "ActiveDocument.Fields.Add Range:=..." all over the document and it
works fine. When the range is myTbl.Columns(1).Cells(1).Range I get "Runtime
error '4605' This command is not available". What am I doing wrong please?
 
C

Chuck Henrich

The table cell range includes the table cell marker. You need to exclude
that by collapsing the range or moving the end eg:

Dim rngRange As Range

Set rngRange = ActiveDocument.Tables(1).Columns(1).Cells(1).Range
rngRange.Collapse wdCollapseStart
ActiveDocument.Fields.Add rngRange, wdFieldDate

or

Dim rngRange As Range

Set rngRange = ActiveDocument.Tables(1).Columns(1).Cells(1).Range
rngRange.MoveEnd wdCharacter, -1
ActiveDocument.Fields.Add rngRange, wdFieldDate
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top