Word
A family of Microsoft word processing software products for creating web, email, and print documents.
686 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I am working on a Word Addin. We are trying to add in MergeFields into a Word document. The code below is working for the Desktop application, and adding a MergeField called 'StartDate' as expected. The same code is not working for the Online application. The range.insertField(...)
is failing with an InvalidArgument.
OfficeExtension.config.extendedErrorLogging = true
Word.run(async (context) => {
var body = context.document.getSelection()
var range = body.getRange().load()
const fieldName = 'StartDate'
range.insertField(
Word.InsertLocation.before,
Word.FieldType.mergeField,
fieldName,
true
)
await context.sync()
}).catch(function (error) {
console.log('Trace Message:' + error.traceMessage)
if (error instanceof OfficeExtension.Error) {
console.log('Trace Message:' + error.traceMessages)
}
})
The error is telling me the problem is at var insertField = range.insertField("Before", "MergeField", "StartDate", true);
.
Any ideas as to why the Online Word is throwing this error?