none
Spurious HeaderFooters created in Word 2003 when automation access Range property RRS feed

  • Question

  • I have a problem with layout being changed due to spurious headers (and footers) being created when doing automated editing of a document (using C++). I have narrowed down the condition to the following:

    A Word 2003 document that has a single line of text in a single page in a single section. It also has text in the primary footer. Nothing else. At this point, a diagnostic added to the automation shows a single HeaderFooter (a Primary Flooter). If I do nothing else, all is well. However, if I them access the Range property of this footer, I suddenly find that I have acquired 5 new headers and footers, all with a newline in them (ie Word has created one of every possible type of HeaderFooter). The easiest way to see this behaviour is to [Show Paragraph Marks]. The same effect can be seen by accessing the Range property (so long as it exists) of any of the 6 possible HeaderFooters in a section.

    Now, out there, in the real world, this behaviour is causing serious concern, as text is getting pushed down the page and tables broken up etc. It would appear, from client feedback, that this problem is present in Word 2000 and Word 2003 but not confined to those versions, but documented evidence to support presence in later versions has not yet been forthcoming.

    So is anybody able to a) replicate this problem and b) have a solution to it.

    Oswy


    Oswy In the Broad Acres
    Thursday, June 30, 2011 4:05 PM

Answers

  • Hi Oswy

    Just a couple of follow-up remarks

    1. RTF: was discontinued as a supported file format with Office 2007 SP2. It's still there, but it's not going to be expanded in any way to cover the functionality of future versions

    2. My link was for the Office binary file formats (*.doc, 97-2003), which are now public

    3. The Office 2007 file formats are actually supported back to Word 2000, as long as the Compatibility Pack is installed. So users/companies can open and, for you more importantly, save in that file format. I suspect requiring your clients to do so is not going to be feasible, but I mention it for the sake of completeness :-)


    Cindy Meister, VSTO/Word MVP
    • Proposed as answer by Calvin_GaoModerator Tuesday, July 19, 2011 3:02 AM
    • Marked as answer by Oswy Tuesday, July 19, 2011 2:09 PM
    Thursday, July 7, 2011 1:04 PM
    Moderator

All replies

  • Hi Oswy

    This kind of question actually turns up more in end-user support groups than developer groups but yes, the behavior is known and "by design". Those end-user questions are usually more along the lines of "why do I see all those grayed-out paragraph marks" and not about the layout changing.

    A document shouldn't be set up such that putting something into the header/footer would cause a problem. The page setup settings should be such that the header/footer is not larger than the top/bottom margins. You might open such a document in Word, go to File/Page Setup (I'm assuming 2003 or earlier, since that's a version you mention) and look at the settings here, paying special heed to 1) Top/Bottom margin and 2) Headers and footers: From Edge.

    I'm guessing that the margins settings are very small and that the From Edge are as large or larger (probably still the default). IOW at some point, someone reduced the size of the margins, but didn't reduce the starting points for the header/footers accordingly. Thus, the issue you're seeing.

    So try reducing the size of the header/footer to: Margin + spece required for the font size

    See if that makes a difference?

     


    Cindy Meister, VSTO/Word MVP
    • Marked as answer by Oswy Friday, July 1, 2011 9:45 AM
    • Unmarked as answer by Oswy Friday, July 1, 2011 9:52 AM
    Friday, July 1, 2011 8:46 AM
    Moderator
  • Hi Cindy,

    Thanks for the reply. It's good to get a definitive statement on this sort of a problem. Unfortunately, as you can imagine, this is not the answer I had hoped for :-)

    Being at the developer end of the food chain, this problem has ramifications for us, as we have close to 100 clients, many of which use around 2000 or so regular documents. Some of these documents are financial statements with legally required content. It is these satements that tend to cause the problem, as the users are struggling to get everything onto the required number of pages. If the master documents have all to be changed, it will be a lot of work for a lot of people. Add to that, the fact that, nationally, over a million of these statements are printed each year, just pushing text onto one additional page, can be a big thing.

    So - if the problem we see, is "by design", then we must, if possible, find a work-around. It occurred to me that it might be possible to remove those spurious headers and footers that were not in the document when it was loaded. Unfortunately, I can't see any way of deleting an existing header or footer. I have tried setting the 'Exists' property to VARIANT_FALSE, but that does not seem to do anything (only just tried this, so I may still have something wrong). If it's not too much of an imposition, may I ask if you  can suggest a suitable work-around.


    Oswy In the Broad Acres
    Friday, July 1, 2011 10:40 AM
  • Hi Oswy

    This kind of behavior started showing up, around Word 97 or 2000. I don't think we saw it in the old WordBasic versions because I can remember people all of a sudden being put out, seeing those paragraph marks. At some point down the road, the Word team built something into the UI that made the paragraph marks disappear if there was no content in the header. Maybe in Word 2007. I've never paid any attention how that does or does not work when working through the programming interface.

    I asked you whether changing the "From edge" setting for  the header / footer fixed the layout problem for you? Because if it does, the simplest (and most correct) fix would be to have you code check those settings (margins/from edge) and if the first is too small to allow the second AND the headers/footers have no content (Range.Text.Length = 1 because there's always a paragraph mark), reduce the size of the "From Edge" setting. Do that before you even run the styles stuff.

    Other than that, you never actually tell us WHY you'd be accessing these header/footer Range properties. Knowing that might help us come up with a workaround.

    Is your app running client side against the versions of Word you mentioned BTW?


    Cindy Meister, VSTO/Word MVP
    Friday, July 1, 2011 2:57 PM
    Moderator
  • Hi Cindy,

    Sorry for the delay, I've been experimenting. The 'from edge' setting will work on some documents, but others report attempts to print outside the printable area. That is a real problem as it throws up the appropriate dialogue box. In one of our software's operating modes, that we call 'Batch Mode', the program is expected to process 1000s of documents without intervention. Most users run this hidden away in their server rooms. Any dialogue box that is displayed will halt the process, and being hidden, cause a major interruption in work flow.

    The reason we're accessing the headres and footers, is to find key words and exchange them for values extracted from an XML that file we are presented with. A bit like a mailmerge but on a somewhat more sophisticated level and specific to the domain, such as letters in Welsh or large print depending on database lookups etc. It is trully amazing how some of our clients bend Word to their will (eg tables and graphics inside the header, and even in the same header).

    > "Is your app running client side against the versions of Word you mentioned BTW"

    I'm always a little confuced about such definitions. The mechanism is as follows:

    Our app picks up an XML file, either as a command line parameter or from a specified folder (mode dependant) then loads various scripts depending on what it finds in the XML, it then makes a decision about which Word document is required. If Word is not already loaded, it is loaded as a COM object, the document is then loaded and manipulated as required. Mostly replacing keywords depending on what is specified in the XML file, but this may involve building tables, numbered lists etc or applying special formating as required. This app started life in 1995 using DDE and WordBasic. It is now in its third incarnation.

    I hope the above helps to provide some of background to what we're doing and the of requirements we have.

    Standing back, and looking at the problem, over the past weekend. It occurs to me that the knubb of the immediate problem we have, is not so much what goes into an individual header (the users can plan for that and expect the value they see), but the appearance of unexpected headers, that the users never created. ie a single primary footer, when edited (pRange = pHdrFtr->Range;) via COM will cause a primary header to appear, along with its attached paragraph mark. It is that new and unexpected paragraph mark that causes the problems.

    Thanks once agin for your help.

     

     

     

     


    Oswy In the Broad Acres
    Wednesday, July 6, 2011 9:10 AM
  • <<the knubb of the immediate problem we have, is not so much what goes into an individual header (the users can plan for that and expect the value they see), but the appearance of unexpected headers, that the users never created. ie a single primary footer, when edited (pRange = pHdrFtr->Range;) via COM will cause a primary header to appear, along with its attached paragraph mark. It is that new and unexpected paragraph mark that causes the problems.>>

    Yes, I was aware of that, but there's nothing you can do to change it as long as you have to do what you're doing.

    And a further problem with all this is that things can differ depending on the printer driver selected when Word opens a document.

    The only way out I can think of is that you don't automate Word at all, but work directly with the closed files. This would be fairly simple if we were talking docx. But when the old file formats are involved, well, things can get very messy. However, that might be the only option open to you. Here's some info:

    Office binary file formats
    - Forum
    - obtaining

    Cindy Meister, VSTO/Word MVP
    Wednesday, July 6, 2011 4:45 PM
    Moderator
  • I was rather afraid that might be the outcome. I shall investigate the file formats further, but we do have an ongoing project to investgigate the use of RTF, but we find that it can get very messy, when users have repeatedly edited their source documents. It would be nice if we could use docx, but only a small proportion of our clients have Word 2007 or later, so we're 'ham-strung', in that respect.

    I think I can sense a severe bout of RTF coming on - wish me luck :-)

    Thank you for your forebearance and assistance in this matter, it is much appeciated. I'll try and report back with what we do --- I may be gone some time.

     


    Oswy In the Broad Acres
    Thursday, July 7, 2011 11:52 AM
  • Hi Oswy

    Just a couple of follow-up remarks

    1. RTF: was discontinued as a supported file format with Office 2007 SP2. It's still there, but it's not going to be expanded in any way to cover the functionality of future versions

    2. My link was for the Office binary file formats (*.doc, 97-2003), which are now public

    3. The Office 2007 file formats are actually supported back to Word 2000, as long as the Compatibility Pack is installed. So users/companies can open and, for you more importantly, save in that file format. I suspect requiring your clients to do so is not going to be feasible, but I mention it for the sake of completeness :-)


    Cindy Meister, VSTO/Word MVP
    • Proposed as answer by Calvin_GaoModerator Tuesday, July 19, 2011 3:02 AM
    • Marked as answer by Oswy Tuesday, July 19, 2011 2:09 PM
    Thursday, July 7, 2011 1:04 PM
    Moderator
  • Hi Oswy,

    Any update on this question?


    Best Regards, Calvin Gao [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, July 19, 2011 3:03 AM
    Moderator
  • Hi Calvin,

    Sorry for all the delay. This problem had been pushed off the top of the pile, until today.

    We've now decided to issue a note to our users, along with guidance for editing their master documents (skeletons), and our help files and manuals are undegoing the necessary changes.

    Longer term, we need to provide a solution, be that an actual fix in our code, or a 'prophylactic' to prevent the users getting into the situation. In either case, we will probably rely on the file formats, either using XML from docx, or, more likely, the binary format as suggested by Cindy. It would have been nice to adopt the latest formats, but if I tell you that it isn't all that long since our last customer with Word 97 moved on to a 'later' version, you'll understand the problem  :-)


    Oswy In the Broad Acres
    Tuesday, July 19, 2011 2:22 PM