Results 1 to 4 of 4
  1. #1
    Star Lounger
    Join Date
    Oct 2011
    Location
    Auckland. New Zealand
    Posts
    61
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Preserving original formatting when inserting text into new document?

    I am updating an existing template that has a button that allows the user to insert a document into the new document created by the template.

    This code has been used to copy text:

    docActive.ActiveWindow.Selection.Range.PasteAndFor mat wdFormatOriginalFormatting

    The trouble is that, while the formatting of the text is correct, all the copied content has the Style "Normal". In other words, in general the text in the new document looks correct (with the exception of bullets), but the Style is "Normal" and not the correct bullet style that was applied in the original document (and has been set up in the template).

    This means my TOC isn't updating with the new heading content, and my actual bullet symbols are 'lost'.

  2. #2
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,054
    Thanks
    2
    Thanked 417 Times in 346 Posts
    That seems to be the 'normal' behaviour. In a way, it's understandable, since that option tells Word to ignore whatever Style definitions exist in the destination document. Once you start doing that, whatever you do is going to use direct formatting for anything that doesn't match the destination Style of the same name, so I suppose MS decided it'd simply apply the Normal Style and direct format that to achieve the desired appearance.
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  3. #3
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,852
    Thanks
    4
    Thanked 259 Times in 239 Posts
    As Paul says, this is just how it works.

    The alternative is to ensure that none of the pasted content uses a style that already exists in the target document. There are macros around that systematically rename all the styles in the document to have a prefix/suffix which makes each used style unique so you can paste and retain the (new) style names without worrying that the style already exists in the target doc. I'm pretty sure I've seen such a macro on this forum years ago but it probably isn't too hard to recreate if you can't find one.
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  4. #4
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,054
    Thanks
    2
    Thanked 417 Times in 346 Posts
    A rather more complicated (and slower) approach would be to use the FormattedText method, which itself quite fast and preserves the Style names and avoids copy/paste, then apply the source paragraph & character formats as hard formatting.
    Cheers,

    Paul Edstein
    [MS MVP - Word]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •