S
Sankalp
Hi,
I have a pop-up menu which is used for removing a bookmarks. When I go
through Word's Bookmark menu, I am able to see all the bookmarks. At the
time of deleting a bookmark through the custom pop-up menu I am also able to
get a valid BookmarkId(say 3). When I try to get the size of the Bookmarks
collection I am returned a size of only one (though more than one bookmark
exists). As a result I am not able to refer to the bookmark I need to
delete.
Is there anything I can do about this? or am I doing something wrong. Why is
this behaviour?
Code below:
HRESULT hr = S_OK;
CComBSTR bsCaption;
CComBSTR bsCompare;
CComPtr<Word::Selection> pSelCurrent;
CComPtr<Word::Bookmarks> pBMColl;
CComPtr<Word::Bookmark> pBMToDel;
hr = Btn->get_Caption(&bsCaption);
bsCompare.LoadString(IDS_BUTTON_POPUP_REMOVETAG);
if (_bstr_t(bsCaption) == _bstr_t(bsCompare)) {
hr = m_pWordApp->get_Selection(&pSelCurrent);
long lngBMIdx = -1;
hr = pSelCurrent->get_BookmarkID(&lngBMIdx); //returns an id of 3
if (lngBMIdx > 0) {
hr = pSelCurrent->get_Bookmarks(&pBMColl);
hr = pBMColl->put_ShowHidden(VARIANT_TRUE);
hr = pBMColl->put_DefaultSorting(Word::wdSortByName);
long lngCount = -1;
hr = pBMColl->get_Count(&lngCount); // returns 1
hr = pBMColl->Item(&CComVariant(lngBMIdx), &pBMToDel); //
this fails
if (NULL != pBMToDel.p) {
hr = pBMToDel->Delete();
}
}
}
Thanks,
Sankalp
I have a pop-up menu which is used for removing a bookmarks. When I go
through Word's Bookmark menu, I am able to see all the bookmarks. At the
time of deleting a bookmark through the custom pop-up menu I am also able to
get a valid BookmarkId(say 3). When I try to get the size of the Bookmarks
collection I am returned a size of only one (though more than one bookmark
exists). As a result I am not able to refer to the bookmark I need to
delete.
Is there anything I can do about this? or am I doing something wrong. Why is
this behaviour?
Code below:
HRESULT hr = S_OK;
CComBSTR bsCaption;
CComBSTR bsCompare;
CComPtr<Word::Selection> pSelCurrent;
CComPtr<Word::Bookmarks> pBMColl;
CComPtr<Word::Bookmark> pBMToDel;
hr = Btn->get_Caption(&bsCaption);
bsCompare.LoadString(IDS_BUTTON_POPUP_REMOVETAG);
if (_bstr_t(bsCaption) == _bstr_t(bsCompare)) {
hr = m_pWordApp->get_Selection(&pSelCurrent);
long lngBMIdx = -1;
hr = pSelCurrent->get_BookmarkID(&lngBMIdx); //returns an id of 3
if (lngBMIdx > 0) {
hr = pSelCurrent->get_Bookmarks(&pBMColl);
hr = pBMColl->put_ShowHidden(VARIANT_TRUE);
hr = pBMColl->put_DefaultSorting(Word::wdSortByName);
long lngCount = -1;
hr = pBMColl->get_Count(&lngCount); // returns 1
hr = pBMColl->Item(&CComVariant(lngBMIdx), &pBMToDel); //
this fails
if (NULL != pBMToDel.p) {
hr = pBMToDel->Delete();
}
}
}
Thanks,
Sankalp