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#
  4. Reading bookmarks in word

Reading bookmarks in word

Scheduled Pinned Locked Moved C#
testingtoolstutorialquestion
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.
  • J Offline
    J Offline
    Jia100
    wrote on last edited by
    #1

    How to open a document using word automation and read the bookmark values in it?This has to be done as a function...input of the function will be the full path of the file to be opened and a list of bookmark names.

    R 1 Reply Last reply
    0
    • J Jia100

      How to open a document using word automation and read the bookmark values in it?This has to be done as a function...input of the function will be the full path of the file to be opened and a list of bookmark names.

      R Offline
      R Offline
      Ravi Sant
      wrote on last edited by
      #2

      There is similar question and solution too given here: how to retrive bookmarks from word document in c#.net[^]

      // ♫ 99 little bugs in the code, // 99 bugs in the code // We fix a bug, compile it again // 101 little bugs in the code ♫

      J 1 Reply Last reply
      0
      • R Ravi Sant

        There is similar question and solution too given here: how to retrive bookmarks from word document in c#.net[^]

        // ♫ 99 little bugs in the code, // 99 bugs in the code // We fix a bug, compile it again // 101 little bugs in the code ♫

        J Offline
        J Offline
        Jia100
        wrote on last edited by
        #3

        Thank you :) but i am not able to goto the bookmark and bookmark names are not displayed(dont know whether i had inserted bookmarks correctly,please check).Following is the code: Word._Application oWord; Word._Document oDoc; oWord = new Word.Application(); oWord.Visible = true; object fileName = strFileName; object readOnly = false; object isVisible = true; object missing = System.Reflection.Missing.Value; object oEndOfDoc = "\\endofdoc"; oDoc = oWord.Documents.Open(ref fileName, ref missing, ref readOnly, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref isVisible, ref missing, ref missing, ref missing, ref missing); oDoc.Activate(); Word.Paragraph oPara1; oPara1 = oDoc.Content.Paragraphs.Add(ref missing); oPara1.Range.Text = "Heading 1"; oPara1.Range.Font.Bold = 1; oPara1.Format.SpaceAfter = 24; oPara1.Range.InsertParagraphAfter(); Word.Paragraph oPara2; object oRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range; oPara2 = oDoc.Content.Paragraphs.Add(ref oRng); oPara2.Range.Text = "Heading 2"; oPara2.Format.SpaceAfter = 6; oPara2.Range.InsertParagraphAfter(); Word.Paragraph oPara3; oRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range; oPara3 = oDoc.Content.Paragraphs.Add(ref oRng); oPara3.Range.Text = "This is a sentence of normal text.Now here is a text"; oPara3.Range.Font.Bold = 0; oPara3.Format.SpaceAfter = 24; oPara3.Range.InsertParagraphAfter(); oDoc.Paragraphs[1].Range.InsertParagraphBefore(); object bm1 = oDoc.Paragraphs[1].Range; Microsoft.Office.Interop.Word.Bookmark bookmark1 = oDoc.Bookmarks.Add("bookmark1", ref bm1); bookmark1.Range.Text = "bm1"; oDoc.Paragraphs[2].Range.InsertParagraphBefore(); object bm2 = oDoc.Paragraphs[2].Range; Microsoft.Office.Interop.Word.Bookmark bookmark2 = oDoc.Bookmarks.Add("bookmark2", ref bm2); bookmark1.Range.Text = "bm2"; int nCount; nCount = oDoc.Bookmarks.Count; for (int i = 0; i < nCount; i++) { object objI = i; MessageBox.Show(oDoc.Bookmarks.get_Item(ref objI).Name); }

        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