Hello,
I'm testing following codes which have been posted here. Following codes work fine.
Now I'd like to define "Style" of oPara2. But the "commented out" code does not execute.
It says Style is not reference property. But "style" is a legitimate property of word object Paragraph, which is the object of oPara2.
Does anybody know what I'm missing?
https://learn.microsoft.com/en-us/office/vba/api/word.paragraph.styleprocedure TForm1.Button2Click(Sender: TObject);
var
Server, Connect : Variant;
oWord, oPara1, oPara2 : Variant;
w:widestring;
begin
if Assigned(InitProc) then
TProcedure(InitProc);
try
Server := CreateOleObject('Word.Application');
except
ShowMessage('Unable to start Word.');
Exit;
end;
oWord := Server.Documents.Add;
Server.Visible := True;
// w := UTF8Decode('d:\temp\mydoc.docx');
// Server.Documents.Open(w);
oPara1 := Server.ActiveDocument.Content.Paragraphs.Add;
oPara1.Range.Text := 'This is a Heading';
oPara1.Range.Font.Bold := True;
oPara1.Format.SpaceAfter := 24;
oPara1.Range.InsertParagraphAfter();
oPara2 := Server.ActiveDocument.Content.Paragraphs.Add;
oPara2.Range.Text := 'Where will this appear if at all!';
oPara2.Range.Font.Bold := False;
oPara2.Format.SpaceAfter := 24;
oPara2.Range.InsertParagraphAfter();
// oPara2.Style := oWord.Styles(1);
end;