Variant vWord, vDocumentos, vDocumento, vSeleccion;
String sPath = ExtractFilePath( Application->ExeName );
String sSrcFile = sPath + "titulo platilla.doc";
String sDestFile = sPath + "titulo resultado.doc";
try {
vWord = Variant::CreateObject( "Word.Application" );
vWord.OlePropertySet( "Visible", false );
}
catch ( ... ) {
MessageBox(0,"Probablemente Microsoft Word no se encuentre instalado", "Error de comunicacion", MB_OK | MB_ICONERROR);
return;
}
//--- Abre el documento que usaremos como plantilla
vDocumentos = vWord.OlePropertyGet( "Documents" );
vDocumento = vDocumentos.OleFunction( "Open",
sSrcFile.c_str(), // Documento
false, // Confirmar conversiones
true, // solo lectura
false, // Añadir al menu de rec.
"" // Pswd del documento¿
);
// AQUI TODO LO QUE VAYAS A HACER
vDocumento.OleProcedure( "SaveAs", sDestFile.c_str() );
vDocumento.OleProcedure( "Close", -1);
vWord.OleProcedure( "Quit" );
vWord = vDocumentos = vDocumento = vSeleccion = Unassigned;