Try it this way. I hope that solves most of your all problems.
Variables used
Name DataType Subtype
wrdApp Automation Automation Server.Application
wrdDoc Automation Automation Server.Document
wrdRange Automation Automation Server.Range
wdGotoBookmark Integer
what Integer
which Integer
count Integer
TemplateName Text 200
Automation Server is {00020905-0000-0000-C000-000000000046} 8.1
or the "Microsoft Word 10.0 Object Library"
(depending on Version of Word used, I prefer using older versions due to compatibilty)
TemplateName := '\\Servername\Name_of_share\folder\wordTemplate.dot';
CREATE(wrdApp);
wrdApp.Visible := TRUE;
IF NOT EXISTS(TemplateName) THEN ERROR (ErrMsgFileNotFound, TemplateName);
wrdDoc := wrdApp.Documents.Add(TemplateName);
wrdApp.ActiveDocument.Fields.Update;
// With Fields in Word
wrdRange := wrdApp.ActiveDocument.Fields.Item(1).Result;
wrdRange.Text := YourText;
// Alternatively print at a Bookmark position
wdGotoBookmark := -1;
what := wdGotoBookmark;
tab[1] := 9;
// which := 1; // Standard for WdGotoFirst
// count := 1; // Standardvalue
wrdRange := wrdDoc.GoTo(what,which,count,textmarke);
wrdRange.InsertAfter('your Text');
wrdRange.InsertAfter(tab);
wrdRange.InsertAfter('Another Text');
wrdRange.InsertParagraphAfter;
// wrdDoc.PrintOut // Print Document to Std. printer
// wrdDoc.PrintPreview; // Show Print preview
wrdApp.Activate;
clear(wrdApp);
hello,
I am attempting to use the code where text is inserted at a bookmark, but i am getting an Error:
"This message is for C/AL Programmers.
This Data type is not supported by C/SIDE. You can access data from any of the following data types.
VT_VOID,VT_I2,VT_I4,VT_R4,VT_R8,VT_CY,VT_DATE,VT_BSTR,VT_BOOL"
Watching debugger, the process is stopped at the wrdRange := wrdDoc.GoTo(what,which,count,textmarke); bit of code.
I have 'what' set to -1, 'which' set to 1, 'count' set to 1 (as per your example), and the 'textmarke' is entered as the name of the bookmark in my document (CLE). What may I be doing wrong?
Comments
I am attempting to use the code where text is inserted at a bookmark, but i am getting an Error:
"This message is for C/AL Programmers.
This Data type is not supported by C/SIDE. You can access data from any of the following data types.
VT_VOID,VT_I2,VT_I4,VT_R4,VT_R8,VT_CY,VT_DATE,VT_BSTR,VT_BOOL"
Watching debugger, the process is stopped at the wrdRange := wrdDoc.GoTo(what,which,count,textmarke); bit of code.
I have 'what' set to -1, 'which' set to 1, 'count' set to 1 (as per your example), and the 'textmarke' is entered as the name of the bookmark in my document (CLE). What may I be doing wrong?
EDIT: solved my own problem! thanks!