get line range with C++ (word 2010)
-
I want to get the range of a line cursor in. VBA code (word2010) looks like this: ================================================ ActiveDocument.Bookmarks.Item("\LINE").Range C++ code looks like this: ================================================ CBookmarks oBookMarks = oDoc.get_Bookmarks(); VARIANT varName; varName.vt = VT_BYREF|VT_I1; char buff[6] = {"\\LINE"}; varName.pcVal = buff; CBookmark0 oBookMark = oBookMarks.Item(&varName); VBA code works perfectly but C++ code triggers some exception(required members does not exist). Anyone knows why? I really appriciate for your help.
-
I want to get the range of a line cursor in. VBA code (word2010) looks like this: ================================================ ActiveDocument.Bookmarks.Item("\LINE").Range C++ code looks like this: ================================================ CBookmarks oBookMarks = oDoc.get_Bookmarks(); VARIANT varName; varName.vt = VT_BYREF|VT_I1; char buff[6] = {"\\LINE"}; varName.pcVal = buff; CBookmark0 oBookMark = oBookMarks.Item(&varName); VBA code works perfectly but C++ code triggers some exception(required members does not exist). Anyone knows why? I really appriciate for your help.
You are passing a string using the
VARIANT
pcVal member. Strings are usually passed using the bstrVal member with typeVT_BSTR
. When using MFC, you may use theCOleVariant
type which creates aVT_BSTR
when passing a string:CBookmark0 oBookMark = oBookMarks.Item(COleVariant(_T("\\LINE")));
Another error may be the name of the used function
oBookmarks.Item()
. Please check if this functions exists. If you have imported a typelib, see the generated header file. With C++ OLE automation, many item access function are namedGetItem()
andSetItem()
. -
You are passing a string using the
VARIANT
pcVal member. Strings are usually passed using the bstrVal member with typeVT_BSTR
. When using MFC, you may use theCOleVariant
type which creates aVT_BSTR
when passing a string:CBookmark0 oBookMark = oBookMarks.Item(COleVariant(_T("\\LINE")));
Another error may be the name of the used function
oBookmarks.Item()
. Please check if this functions exists. If you have imported a typelib, see the generated header file. With C++ OLE automation, many item access function are namedGetItem()
andSetItem()
.