Answer the question
In order to leave comments, you need to log in
How to add a field with a variable to a Word file via COM in 1C?
Task: implement printing in word using custom word templates. At the moment, I have implemented data filling using fields with the DocVariable type. But there is one difficulty: the user himself will not be able to add fields before loading the template in 1C. I want to programmatically add fields via COM.
I tried to analyze the code that is obtained when recording a macro. The code itself:
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:= _
"DOCVARIABLE текст1 ", PreserveFormatting:=True
ОбъектВорд = Новый COMОбъект("Word.Application");
ОбъектВорд.Documents.add(ПараметрыПечати.ФайлМакета.АдресВХранилище);
ДокументВорд = ОбъектВорд.Application.ActiveDocument;
ДокументВорд.Activate();
ОбъектВорд.Selection.Fields.Add(ОбъектВорд.Selection.Range, как_то_указать_тип, "DOCVARIABLE текст1 ", True);
Answer the question
In order to leave comments, you need to log in
This is a numeric constant:
https://msdn.microsoft.com/en-us/vba/word-vba/arti... Put a
number.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question