Problem using Paragraph.ID property as Word randomly resets it. RRS feed

  • Question

  • I have an external process that is exporting a document into Microsoft Word using OLE automation.

    This process sets the Paragraph.ID property for each paragraph exported, as this allows cross referencing to headings and captions to be performed once all of the document has been exported. The paragraphs are created by copying data into the system clipboard and pasting it into Word (the clipboard is being used as this retains rich text formatting).

    I'm seeing an intermittent issue where Word resets the ID to null/empty string for a large number of paragraphs, thus making the ID property volatile and unusable.

    The online documentation for this property is sparse and not very helpful.

    Is this property usable?

    What circumstances cause the ID field to be reset?

    Are there any alternatives that I could use - either another property or some other means of tagging each paragraph? Note I don't want to use content controls as this there are ~30000 paragraphs in the exported document.

    I should have mentioned I'm using Word 2016.

    Tuesday, February 13, 2018 4:18 PM

All replies

  • Hi The Nybbler,

    Are you trying to save the document as web page?

    As per documentation, It Returns or sets the identifying label for the specified object when the current document is saved as a Web page.

    Also if you set for Range then it will not work.

    Microsoft Word does not store the ID property setting for a Range object. If you set the ID property and then return its value, the returned value will be an empty string.


    Paragraph.ID Property



    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact

    Wednesday, February 14, 2018 8:59 AM
  • How about inserting a point bookmark with a sequence number in each paragraph, e.g.

    id1 for para. 1, id2 for para. 2, and so on.

    e.g. using something like

    Sub insertbmperpara()
    Const idPrefix As String = "idprefix"
    Dim lng As Long
    Dim p As Word.Paragraph
    lng = 0
    For Each p In ActiveDocument.Paragraphs
      lng = lng + 1
      p.Range.Bookmarks.Add idPrefix & CStr(lng)
      ' give ourselves a break every so often
      If lng Mod 1000 = 0 Then
      End If
    End Sub

    If you need to tag paragraphs that are "out-of-line" ( in headers/footers/footnotes etc.) there would be a little bit more to it. 

    Peter Jamieson

    Sunday, February 18, 2018 12:34 PM