none
Replacing the entire WordML contents of a document RRS feed

  • Question

  • Hi

    I have made some code that modifies the WordML content of my document. I'm having trouble figuring out how to insert the modified WordML back into my document replacing the original content. I have looked a lot at ranges but it seems they are only operating on the xml contents of the document - not the entire WorldML.

    Can anyone help?
    Thursday, July 9, 2009 6:30 AM

Answers

  • Hi Claus

    Well, this button corresponds to the internal "Footnotes" command, the description of which: "Opens a pane for viewing and editing the notes (toggle)".

    (I got this by:     Set btn = Application.CommandBars.FindControl(ID:=764)
        Debug.Print btn.Caption & btn.DescriptionText )

    FWIW I don't know the nitty-gritty about footnotes/endnotes. That would be covered in the "general questions" Word newsgroup (word.docmanagement). However, to put it very simply, the user should not be doing what he's doing if he's changing the footnote reference number in the footnote. That number is basically plain text that's been superscripted and marked by Word (the little lines around the number). Changing that number will not change the footnote reference in the text - trying to change that will cause a warning message to display.

    This is basically a question of user education: If the user wants that number to change, he has to change the number of footnotes preceding the one in question - in the text, not in the footnote pane. (Add an additional footnote, in your example).

    The Footnote pane is for editing the footnote text, not for managing the footnotes in the document.  Word provides no separate functionality (pane, dialog box, window) for managing all footnotes in the document. They are managed (added/deleted) in the text flow. If "they" want something to manage footnotes, then it's going to have to be built up from scratch ("View notes" is going to have to display something else than the built-in tool).

    Note that
    1) the footnote pane is not used in the primary (print layout) view, only in the "Normal" view. These days, it's usually no longer necessary to work in that view - machines are fast enough to process the WYSI(A)WYG view. In that view, the footnotes appear where they would on the page.

    2) In print layout view, double-clicking a footnote reference number will jump the user to that position in the document, resp. from within the text to the footnote (at least, that's what I'm seeing in 2007).
    Cindy Meister, VSTO/Word MVP
    • Marked as answer by Claus Jessing Friday, July 10, 2009 5:22 AM
    Thursday, July 9, 2009 1:02 PM
    Moderator

All replies

  • Hi Claus

    Best you can do, via the "interop" is:

    document.Content.InsertXML stringValidWordProcessingML

    If there are things that this does not include in the resulting document, then you must use the Interop to make the necessary corrections.

    While it is possible to read and write WordProcessingML in Word 2003, it was never the intention that entire documents should be written or read while open in the applicaton interface. The XML file format was conceived in order to allow closed documents to be manipulated, without requiring the application UI to be running. The Interop exists for working in the running application.
    Cindy Meister, VSTO/Word MVP
    Thursday, July 9, 2009 6:43 AM
    Moderator
  • Thanks for a quick answer Cindy!

    What I'm trying to do - but has so far been unsuccessful - is to keep the foot and end notes in sync when the user alters the reference number in the actual note text. If I have a footnote number 123. and in the note window change the number to 124 then the number in the document remains unchanged. I would obviously prefer to modify the document using the normal api's but I have not been able to figure out how to update the document when the note number is altered...
    Thursday, July 9, 2009 6:58 AM
  • Hi Claus

    I'm not following what you have...

    When you say "note number" you mean the number of the footnote, or the text the footnote contains?

    It's not possible to change the reference number of a footnote in a Word document - Word itself manages these numbers. It's not possible to assign arbitrary numbers, Word will enforce their being consecutive, in the order the footnote references are listed in the text flow. (Yes, you could make a change in the closed WordProcessingML, but if that doesn't damage the document so Word can't work with it correctly, then Word should correct it when the document is opened.)
    Cindy Meister, VSTO/Word MVP
    Thursday, July 9, 2009 7:06 AM
    Moderator
  • Well... I hope you will excuse my lack of knowledge of the solution I'm working on as I have only entered the project after the product has gone through 2-3 iterations already and a lot of the code has already been written.

    What I have is this: The user clicks a custom "View notes" button resulting in this piece of code being executed:

                        CommandBarControl cbarCtrl = _document.Application.CommandBars.FindControl(MsoControlType.msoControlButton, 764, null, null);
                        if (cbarCtrl != null)
                            cbarCtrl.Execute();

    I have absolute no idea what 764 is but the result is a small window being displayed below the active document listing the notes (footnotes, endnotes and a custom note type). In this window the user can actually update the note reference leaving the reference in this window and the corresponding reference in the document out of sync. Hovering the mouse over the note reference in the document displays the modified note reference in the yellow tool tip window.

    Does this clear things up a bit? Can I post screen shots somehow?
    Thursday, July 9, 2009 7:18 AM
  • Hi Claus

    Well, this button corresponds to the internal "Footnotes" command, the description of which: "Opens a pane for viewing and editing the notes (toggle)".

    (I got this by:     Set btn = Application.CommandBars.FindControl(ID:=764)
        Debug.Print btn.Caption & btn.DescriptionText )

    FWIW I don't know the nitty-gritty about footnotes/endnotes. That would be covered in the "general questions" Word newsgroup (word.docmanagement). However, to put it very simply, the user should not be doing what he's doing if he's changing the footnote reference number in the footnote. That number is basically plain text that's been superscripted and marked by Word (the little lines around the number). Changing that number will not change the footnote reference in the text - trying to change that will cause a warning message to display.

    This is basically a question of user education: If the user wants that number to change, he has to change the number of footnotes preceding the one in question - in the text, not in the footnote pane. (Add an additional footnote, in your example).

    The Footnote pane is for editing the footnote text, not for managing the footnotes in the document.  Word provides no separate functionality (pane, dialog box, window) for managing all footnotes in the document. They are managed (added/deleted) in the text flow. If "they" want something to manage footnotes, then it's going to have to be built up from scratch ("View notes" is going to have to display something else than the built-in tool).

    Note that
    1) the footnote pane is not used in the primary (print layout) view, only in the "Normal" view. These days, it's usually no longer necessary to work in that view - machines are fast enough to process the WYSI(A)WYG view. In that view, the footnotes appear where they would on the page.

    2) In print layout view, double-clicking a footnote reference number will jump the user to that position in the document, resp. from within the text to the footnote (at least, that's what I'm seeing in 2007).
    Cindy Meister, VSTO/Word MVP
    • Marked as answer by Claus Jessing Friday, July 10, 2009 5:22 AM
    Thursday, July 9, 2009 1:02 PM
    Moderator