Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. get line range with C++ (word 2010)

get line range with C++ (word 2010)

Scheduled Pinned Locked Moved C / C++ / MFC
c++helpquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    BCN 163
    wrote on last edited by
    #1

    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.

    J 1 Reply Last reply
    0
    • B BCN 163

      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.

      J Offline
      J Offline
      Jochen Arndt
      wrote on last edited by
      #2

      You are passing a string using the VARIANT pcVal member. Strings are usually passed using the bstrVal member with type VT_BSTR. When using MFC, you may use the COleVariant type which creates a VT_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 named GetItem() and SetItem().

      B 1 Reply Last reply
      0
      • J Jochen Arndt

        You are passing a string using the VARIANT pcVal member. Strings are usually passed using the bstrVal member with type VT_BSTR. When using MFC, you may use the COleVariant type which creates a VT_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 named GetItem() and SetItem().

        B Offline
        B Offline
        BCN 163
        wrote on last edited by
        #3

        thanks very much. the problem is solved. The reason is that I used the wrong VARIANT type.(I am puzzled on using VARIANT)

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups