A
So, ich habe jetzt durch Eibinden der typelib für Word das wie folgt gelöst:
void CAutoProjectDlg::OnBnClickedRun()
{
// TODO: Fügen Sie hier Ihren Kontrollbehandlungscode für die Benachrichtigung ein.
CApplication app; // app is the Word _Application object
// Start Word and get Application object.
if(!app.CreateDispatch(_T("Word.Application")))
{
AfxMessageBox(_T("Cannot start Word and get Application object."));
return;
}
// Make the application visible and give the user control of
// Microsoft Word.
app.put_Visible(TRUE);
// get the document list
CDocuments docs(app.get_Documents());
COleVariant varOPt(DISP_E_PARAMNOTFOUND, VT_ERROR); // unused param
// Open a Word doc
CComVariant Filename = _T("D:\\Doc1.docx");
// Open the file
CDocument0 doc = docs.Open(&Filename, varOPt, varOPt, varOPt, varOPt, varOPt, varOPt, varOPt, varOPt, varOPt, varOPt, varOPt, varOPt, varOPt, varOPt, varOPt);
// Get the formfield list
CFormFields formfields(doc.get_FormFields());
// Choose a formfield
CComVariant Index=_T("Tag_Test");
CFormField formfield = formfields.Item(&Index);
// Change the result
formfield.put_Result(_T("Test"));
// Save Document
//doc.Save();
// Print the Document
doc.PrintOut(varOPt, varOPt, varOPt, varOPt, varOPt, varOPt, varOPt, varOPt, varOPt, varOPt, varOPt, varOPt,varOPt,varOPt,varOPt, varOPt,varOPt,varOPt);
// Close Document
doc.Close(varOPt, varOPt, varOPt);
// Exit Word
app.Quit(varOPt, varOPt, varOPt);
}
Es funktioniert soweit ganz gut.