Is the way that to DisableAutoMacros when open a word document by navigate2 of Chtmlview right?

K

ksun

I use the following code to disable auto macros in the event
OnNavigateComplete2() of CHtmlView, but it seems it does not success.

LPDISPATCH pDispHtmlDocument = GetHtmlDocument();
MSWORD::_Document oDoc = pDispHtmlDocument;
if(oDoc)
{
MSWORD::_Application app = oDoc.GetApplication();
if(app)
{
COleDispatchDriver oWordBasic;
oWordBasic = app.GetWordBasic();
HRESULT hr;
OLECHAR FAR* szMethod[2];
DISPID dispid[2];

szMethod[0] =OLESTR("DisableAutoMacros"); // method name;
//szMethod[1] = OLESTR("Disable");
//szMethod[1] = OLESTR("");
hr = oWordBasic.m_lpDispatch->GetIDsOfNames(IID_NULL, szMethod, 1,
LOCALE_USER_DEFAULT, dispid);

VARIANT vArgs[1];
DISPPARAMS dp;
dp.cArgs = 1;
dp.cNamedArgs = 0;
dp.rgvarg = vArgs;
//dp.rgdispidNamedArgs = &(dispid[1]);
vArgs[0].vt = VT_I2;
vArgs[0].iVal = 1;

VARIANT* pVarResult = NULL;
EXCEPINFO* pExcepInfo = NULL;
UINT* pInt = NULL;
try
{
hr = oWordBasic.m_lpDispatch->Invoke(dispid[0],
IID_NULL,LOCALE_USER_DEFAULT, /*DISPATCH_PROPERTYPUT*/
DISPATCH_METHOD, /*&dpNoArgs*/&dp, pVarResult, pExcepInfo, pInt);


After the method "Invoke", the return value is none of the following
values:
S_OK,
DISP_E_BADPARAMCOUNT,
DISP_E_BADVARTYPE,
DISP_E_EXCEPTION,
DISP_E_MEMBERNOTFOUND,
DISP_E_NONAMEDARGS,
DISP_E_OVERFLOW,
DISP_E_PARAMNOTFOUND,
DISP_E_TYPEMISMATCH,
DISP_E_UNKNOWNINTERFACE,
DISP_E_UNKNOWNLCID,
DISP_E_PARAMNOTOPTIONAL

Is there anything wrong in the above code?
 
H

Howard Kaikow

You have to create a Word object, say, appWord, then use the equivalent of

appWord.WordBasic.DisableAutoMacros
You have to use the equivalent of

With appWord.WordBasic
If blnEnable Then ' to enable
.DisableAutoMacros 0
Else
.DisableAutoMacros 1 ' to disable
End If
End With
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top