How to add a Word.WdFieldType to a word table with vb.net

Eugene Gough 196 Reputation points
2022-05-12T16:55:17.167+00:00

I am creating a document that needs a header with the build date, page number and total pages. Word has several functions that will do that but attempts to use them in a table causes a run time error from Interop,
{"This command is not available."} Note that I know the table is valid as the "test" shows up in the proper cell if the add field is disabled.

Simple example of the failure

Dim tbrng As Word.Range = table1.Rows(rowCount).Cells(1).Range
tbrng.InsertAfter("test")
tbrng.Fields.Add(tbrng, Word.WdFieldType.wdFieldDate)

Microsoft 365 and Office | Development | Other
Developer technologies | Visual Basic for Applications
Developer technologies | VB
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.