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)

VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,751 questions
Office Development
Office Development
Office: A suite of Microsoft productivity software that supports common business tasks, including word processing, email, presentations, and data management and analysis.Development: The process of researching, productizing, and refining new or existing technologies.
4,060 questions
{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.