Posted 20 August 2023, 7:36 am EST
My code searches through documents for complex fields and if the complex field is a mail merge field it adds text as a run after the complex field then it deletes the complex field. I want the new text to have the same font as the complex field. I cannot figure out how to set the font for the new text.
For example, the attached document has complex fields where the font is bold for the complex fields. When I run the following code the font of the added text is not bold. Everything that I have tried to set the font for the new run gives me an error.
Dim FileNameSource As String = “C:\temp\labreport.docx”
Dim Doc1 As New GrapeCity.Documents.Word.GcWordDocument Dim DocSec1 As GrapeCity.Documents.Word.Section Dim DocSecRange1 As GrapeCity.Documents.Word.Range Dim ComplexField1 As GrapeCity.Documents.Word.ComplexField Dim Run1 As GrapeCity.Documents.Word.Run Dim FontComplectField1 As GrapeCity.Documents.Word.Font 'Load the template Doc1.Load(fileName:=FileNameSource) DocSec1 = Doc1.Body.Sections.First DocSecRange1 = DocSec1.GetRange() If DocSecRange1.ComplexFields.Count > 0 Then ComplexField1 = DocSecRange1.ComplexFields(0) FontComplectField1 = ComplexField1.GetRange().Runs.Last.Font Run1 = ComplexField1.GetRange().Runs.Insert("", location:=InsertLocation.After) Run1.GetRange().Texts.Add("XXXXXXXXXX") ComplexField1.Delete() End If