OLE Automation "DisplayRulers is not a method"

M

murugan U

Hello,

I am trying to automate word 2003 to Compare Documents in Tile View
(Compare Side By Side).
I am working on Windows-XP (SP2), Visual Studio 6.0. i am getting the
Error msg "DisplayRulers is not a method" while calling
CompareSideBySideWith.
Here is my code:

CoInitialize(NULL);
_Application objWordApp;
_Document objDoc,objDoc1;
LPDISPATCH lpDisp,lpDisp1;
// Common OLE variants that are easy to use for calling arguments.
COleVariant covTrue((short)TRUE),
covFalse((short)FALSE),
covOptional((long)DISP_E_PARAMNOTFOUND, VT_ERROR);



if ( !objWordApp.CreateDispatch("Word.Application") )
{
MessageBox("Couldn't start MS-Word", "CBayOnlineViewer", MB_OK |
MB_ICONINFORMATION);
return;
}
objWordApp.SetVisible(TRUE);

Documents docs(objWordApp.GetDocuments());


lpDisp = docs.Open(
COleVariant("c:\\test1.doc", VT_BSTR),
covFalse, // Confirm Conversion.
covFalse, // ReadOnly.
covFalse, // AddToRecentFiles.
covOptional, // PasswordDocument.
covOptional, // PasswordTemplate.
covFalse, // Revert.
covOptional, // WritePasswordDocument.
covOptional, // WritePasswordTemplate.
covOptional, // Format. // Last argument
covOptional, // Encoding // New for Word 2000/2002
covTrue, // Visible
covOptional, //OpenAndRepair
covOptional, //DocumentDirection
covOptional, //NoEncodingDialog
covOptional //XMLTransform
); // Close Open parameters


Documents docs1(objWordApp.GetDocuments());
lpDisp1 = docs1.Open(
COleVariant("c:\\test2.doc", VT_BSTR),
covFalse, // Confirm Conversion.
covFalse, // ReadOnly.
covFalse, // AddToRecentFiles.
covOptional, // PasswordDocument.
covOptional, // PasswordTemplate.
covFalse, // Revert.
covOptional, // WritePasswordDocument.
covOptional, // WritePasswordTemplate.
covOptional, // Format. // Last argument
covOptional, // Encoding // New for Word 2000/2002
covTrue, // Visible
covOptional, //OpenAndRepair
covOptional, //DocumentDirection
covOptional, //NoEncodingDialog
covOptional //XMLTransform
); // Close Open parameters


objDoc.AttachDispatch(lpDisp);
objDoc.Activate();

objDoc1.AttachDispatch(lpDisp1);
objDoc1.Activate();
Windows objwin;
objwin.AttachDispatch(objDoc1.GetActiveWindow());
objwin.CompareSideBySideWith(COleVariant("c:\\test1.doc"));
objwin.Arrange(COleVariant ((short)0));

CoUninitialize();

can someone help me out? is there any way to get this work?

Thanks,
Murugan U
 
M

Manvir Singh

Hi Murugan,

There are two things that I noticed in the code snippet:

1. The Windows object should be initialized with Document.Windows
collection. For e.g.:

objwin.AttachDispatch(objDoc1.get_Windows()); //Initialize Windows
object with Document.Winodws collection of second document.

2. Windows.CompareSideBySideWith needs a VARIANT as input. Here is how you
can do this:

VARIANT varDoc;
VariantInit(&varDoc);
varDoc.vt = VT_DISPATCH;
varDoc.pdispVal = objDoc.m_lpDispatch; // Initialize pdispVal with
IDispatch* of first document object.

objwin.CompareSideBySideWith(&varDoc); // Pass the variant to
Windows object.


You can also refer to
http://msdn.microsoft.com/en-us/library/aa171865(office.11).aspx for a VBA
based example.

Hope this helps.

Regards,
Manvir Singh
 
M

murugan U

Hi Murugan,

There are two things that I noticed in the code snippet:

1. The Windows object should be initialized with Document.Windows
collection. For e.g.:

objwin.AttachDispatch(objDoc1.get_Windows()); //Initialize Windows
object with Document.Winodws collection of second document.

2. Windows.CompareSideBySideWith needs a VARIANT as input. Here is how you
can do this:

VARIANT varDoc;
VariantInit(&varDoc);
varDoc.vt = VT_DISPATCH;
varDoc.pdispVal = objDoc.m_lpDispatch; // Initialize pdispVal with
IDispatch* of first document object.

objwin.CompareSideBySideWith(&varDoc); // Pass the variant to
Windows object.

You can also refer tohttp://msdn.microsoft.com/en-us/library/aa171865(office.11).aspxfor a VBA
based example.

Hope this helps.

Regards,
Manvir Singh

Hi Manvir Singh,
thanks!! problem solved!
Thanks a lot! Seriously, a LOT! :)
Regards,
Murugan U
 

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