// JP opened flex table

Click to See Complete Forum and Search --> : Problem with MSWord component!


tuyle
December 10th, 2001, 06:10 AM
I use MSWord component in my project. I create a new MSWord document with name such as "d:\temp\mydoc1.doc" from template (example mytempate.dot). This template contain a macro to insert a text into document.

It runs OK even there are some MSWord applications (instances) currently open unless "mydoc1.doc"

Please see these codes:

int ret = NO_ERR;
CString strMacroName;
CStringList argList;

strMacroName = _T("LC_WriteText");
argList.AddHead("This is a text");
ret = CallMacro(strMacroName,&argList);

........


int CExportMSWord::CallMacro(CString& strMacroName, CStringList* pArgList)
{
int bRetVal = NO_ERR;

HRESULT hr = S_OK;

ASSERT(m_pWrdDoc != NULL
&& m_pWrdDoc->m_lpDispatch != NULL);

OLECHAR FAR* strMacro = strMacroName.AllocSysString();
DISPID dispid;

// Error occurs here
hr = m_pWrdDoc->m_lpDispatch->GetIDsOfNames(IID_NULL, &strMacro, 1, LOCALE_SYSTEM_DEFAULT, &dispid);

SysFreeString(strMacro);

if (FAILED(hr))
bRetVal = UNABLE_CALL_MACRO;
//Some codes....
}




Now I create a new document (mydoc2.doc) from template.dot. Initialize MSWord OK! Create new document OK.

When there is a document which was created from mytemplate.dot (mydoc1.doc) currently open, after executing CallMacro, hr = DISP_E_UNKNOWNNAME!

But if I close "mydoc1.doc", execute again, CallMacro runs OK (hs = S_OK).

Could you tell me what problem and how to fix it??

Thanks in advance
Tuy Le

//JP added flex table