leeseifer
asked on
create an instance of Microsoft Word using Com Automation
hi everyone
I wanna write a small form in c++(a simple dialog box) with 1 button on it.
When i click on the button, create an instance of Microsoft Word using Com Automation, create a new document and write some text in the document.
I wanna write a small form in c++(a simple dialog box) with 1 button on it.
When i click on the button, create an instance of Microsoft Word using Com Automation, create a new document and write some text in the document.
u can use shell command or shellexecute
however for automation see following links
http://www.kbalertz.com/kb_183599.aspx
http://support.microsoft.com/default.aspx?scid=http://support.microsoft.com:80/support/kb/articles/q196/7/76.asp&NoWebContent=1
http://www.kbalertz.com/kb_183599.aspx
http://support.microsoft.com/default.aspx?scid=http://support.microsoft.com:80/support/kb/articles/q196/7/76.asp&NoWebContent=1
Give this a try
COleVariant var;
_Application application;
var.vt = VT_ERROR;
var.scode = DISP_E_PARAMNOTFOUND;
application.CreateDispatch (_T("word. applicatio n"));
application.SetVisible(Vis ible);
Documents documents = application.GetDocuments() ;
_Document document = documents.Add(var,var);
Range range = document.Range(var,var);
range.InsertAfter(_T("hell o"));
COleVariant var;
_Application application;
var.vt = VT_ERROR;
var.scode = DISP_E_PARAMNOTFOUND;
application.CreateDispatch
application.SetVisible(Vis
Documents documents = application.GetDocuments()
_Document document = documents.Add(var,var);
Range range = document.Range(var,var);
range.InsertAfter(_T("hell
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hey i did it... But How do i add bookmark automaticaly?????
Hi again,
U cannot add bookmark automatically, May be u can write something like this. You have to select the BookMark from the MSWORD.OLB
_Document document ;
Bookmarks oBks(document .GetBookmarks());
CString csBk;
csBk.Format("B_%d",nBkPos) ;
VARIANT vtBkRange;
vtBkRange.vt = VT_ERROR;
vtBkRange.scode = DISP_E_PARAMNOTFOUND;
oBks.Add(csBk,&vtBkRange);
Regards,
RKM
U cannot add bookmark automatically, May be u can write something like this. You have to select the BookMark from the MSWORD.OLB
_Document document ;
Bookmarks oBks(document .GetBookmarks());
CString csBk;
csBk.Format("B_%d",nBkPos)
VARIANT vtBkRange;
vtBkRange.vt = VT_ERROR;
vtBkRange.scode = DISP_E_PARAMNOTFOUND;
oBks.Add(csBk,&vtBkRange);
Regards,
RKM
ASKER
Hi there
I try to add the exist document into Word.
docPtr = appPtr->Documents;
_docPtr = docPtr->Add();
These code will add blank Document. But i wanna add a exist file document.
I saw "(VARIANT *Template = &vnMissing)" in Add method ...How can i do with it?????
Thanks Advance
I try to add the exist document into Word.
docPtr = appPtr->Documents;
_docPtr = docPtr->Add();
These code will add blank Document. But i wanna add a exist file document.
I saw "(VARIANT *Template = &vnMissing)" in Add method ...How can i do with it?????
Thanks Advance
simple.. how do u do that in WinWord...Open it..!!
CString csFirstFile = "c:\Myfile.rtf";
vtFirstFile.bstrVal = csFirstFile.AllocSysString ();
VARIANT vtNull, vtFalse;
vtNull.vt = VT_ERROR ;
vtNull.scode = DISP_E_PARAMNOTFOUND ;
vtFalse.vt = VT_BOOL ;
vtFalse.boolVal = VARIANT_FALSE ;
_Application application;
application.CreateDispatch (_T("word. applicatio n"));
application.SetVisible(Vis ible);
Documents oDocuments= application.GetDocuments() ;
_Document oDoc;
oDoc = oDocuments.Open(&vtFirstFi le, &vtNull, &vtNull,&vtNull,&vtNull,&v tNull,&vtN ull,&vtNul l,&vtNull, &vtNull,&v tNull,&vtF alse,&vtFa lse,&vtNul l,&vtNull) ;
The Parameters will change with the MSWord version, like this is for MSWordXP, You have to add one more &vtNull for MSWord2003.
You will get used to it.. ;). AND Beware of memory leaks.
Cheers,
RKM
CString csFirstFile = "c:\Myfile.rtf";
vtFirstFile.bstrVal = csFirstFile.AllocSysString
VARIANT vtNull, vtFalse;
vtNull.vt = VT_ERROR ;
vtNull.scode = DISP_E_PARAMNOTFOUND ;
vtFalse.vt = VT_BOOL ;
vtFalse.boolVal = VARIANT_FALSE ;
_Application application;
application.CreateDispatch
application.SetVisible(Vis
Documents oDocuments= application.GetDocuments()
_Document oDoc;
oDoc = oDocuments.Open(&vtFirstFi
The Parameters will change with the MSWord version, like this is for MSWordXP, You have to add one more &vtNull for MSWord2003.
You will get used to it.. ;). AND Beware of memory leaks.
Cheers,
RKM