Open Specifications Developer Center > Open Specifications Forums > Interoperability Scenarios: Technical Questions > Publisher PIA change of behavior for TextRange.Text between Office 2003 and 2007
Ask a questionAsk a question
 

AnswerPublisher PIA change of behavior for TextRange.Text between Office 2003 and 2007

  • Friday, July 10, 2009 12:21 PMBob Eaton Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    I have a .Net-based COM add-in that works in Publisher in which I go thru the "Stories" one-by-one and change the encoding of words (also, one-by-one) in-situ.

    I iterate the Paragraphs in a Story and for each Paragraph, I use a TextRange object to isolate a single word (and it's following space) to do
    the replacement. So, for example, if I had a Paragraph that contained:

    // aTextRange.Text == "This is a paragraph\r";

    Then I would make a working copy of that TextRange and set the Start = 0 (the beginning of the range) and the End = 5 (the offset of the 'i' in 'is') and this would result in:

    // myTextRange.Text == "This "

    Then I select that range (i.e. myTextRange.Select()) and then set the ".Text" property to my new encoding of that word (e.g. for Piglatin,
    "myTextRange.Text = "Isthay ").

    Now the problem: in Office 2003, even though my replacement text is longer, it only replaces the selected portion of the original range (resulting in the original range becoming "Isthay is a paragraph\r"), which is what I want.

    But in Office 2007, it seems to ignore what portion of the TextRange is selected and replaces the length of the new string (resulting in the
    original range becoming "Isthay paragraph"--I.e. clobbering the next word(s), because the replacement string is longer than the original word).

    Is there some way to work around this? That is, I know that I can use the _Application.Version to detect whether I'm talking to Publisher 2003 or 2007 and treat them differently, but I'm not sure how to work with the TextRange object in 2007 to make it behave like the 2003 PIA does.

    Any ideas?

    Thanks,
    Bob

    P.S. This is only a problem with the Publisher PIAs. I do the same thing in Excel, Access, and Word (of course, with the RangeText object, instead), and it works the same in both the 2003 and 2007 versions.

Answers

All Replies