I
I
Ilya Brazhnikov2018-06-13 02:04:09
1C-Enterprise
Ilya Brazhnikov, 2018-06-13 02:04:09

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

That is, as I understand it, I need something like:
ОбъектВорд = Новый COMОбъект("Word.Application");
  
ОбъектВорд.Documents.add(ПараметрыПечати.ФайлМакета.АдресВХранилище);
  
ДокументВорд = ОбъектВорд.Application.ActiveDocument;
  
ДокументВорд.Activate();
  
ОбъектВорд.Selection.Fields.Add(ОбъектВорд.Selection.Range,  как_то_указать_тип, "DOCVARIABLE  текст1 ", True);

But how to specify Type, I could not figure it out. And whether Range is correctly specified is also a question.
I would be grateful for help.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Yudakov, 2018-06-13
@Ilyabr

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 question

Ask a Question

731 491 924 answers to any question