none
Font is changed when selection copy from word 2003 template to word 2010 RRS feed

  • Question

  • Hi all,

    I encounter a problem which needs the expertise to give me a light to this.

    I am working on an application to merge multiple copy of document word 2003 templates into

    word 2010, it usually try to merge three difference files (all are in word 2003 but in difference

    font format), but as one developer writes the following codes to ensure such that format can

    be bought to new file:

    Function set_style_detail_for_2010(ad_target_document As Document, ad_source_document As Document, as_style_name As Long)

        ad_target_document.Styles(as_style_name).Font = ad_source_document.Styles(as_style_name).Font

        ad_target_document.Styles(as_style_name).BaseStyle = ad_source_document.Styles(as_style_name).BaseStyle

        ad_target_document.Styles(as_style_name).ParagraphFormat = ad_source_document.Styles(as_style_name).ParagraphFormat

        'ad_target_document.Styles(as_style_name).AutomaticallyUpdate = ad_source_document.Styles(as_style_name).AutomaticallyUpdate

        'ad_target_document.Styles(as_style_name).Borders = ad_source_document.Styles(as_style_name).Borders

        'ad_target_document.Styles(as_style_name).LinkStyle = ad_source_document.Styles(as_style_name).LinkStyle

        'ad_target_document.Styles(as_style_name).NameLocal = ad_source_document.Styles(as_style_name).NameLocal

        ad_target_document.Styles(as_style_name).NextParagraphStyle = ad_source_document.Styles(as_style_name).NextParagraphStyle

        'ad_target_document.Styles(as_style_name).NoProofing = ad_source_document.Styles(as_style_name).NoProofing

        'ad_target_document.Styles(as_style_name).NoSpaceBetweenParagraphsOfSameStyle = ad_source_document.Styles(as_style_name).NoSpaceBetweenParagraphsOfSameStyle

        'ad_target_document.Styles(as_style_name).QuickStyle = ad_source_document.Styles(as_style_name).QuickStyle

        'ad_target_document.Styles(as_style_name).UnhideWhenUsed = ad_source_document.Styles(as_style_name).UnhideWhenUsed

    End Function

    One reason we use the above codes to set format on new word file content is that we encounterd some formatting

    are lost during "selection copy" from word 2003 to 2010 file.

    However, now we encounter another problem is that if we merge three word 2003 files, let's file A, B and C.

    This statement,

    ad_target_document.Styles(as_style_name).Font = ad_source_document.Styles(as_style_name).Font

    will use the font in file C overwrite the merge file A and B, for example, if file A and file B uses "Times News Roman"

    and file C uses "Arial", then the final file will use "Arial" for entire file content.

    I have searched the web and someone suggests to use the following option

    PasteAndFormat Type:=wdFormatOriginalFormatting

    but we found the above codes may not be used (quite complicated to explain but the above codes affect "header" in each page of final word content, not really clear the reason at this moment)

    I really want to know if experts can contribute some idea to me how to proceed now.

    Our old marco use mainly "selection copy" and then "paste" operation to another word for merging.

    Not sure this approach is correct, but we need to continue to adopt this as not easy to have big changes on our macro.

    Any idea is welcome and be appreciated.

    Thanks for your assistance in advance,

    Ray
    • Moved by George123345 Friday, July 11, 2014 1:32 AM develop issue
    Thursday, July 10, 2014 3:38 PM

All replies

  • Hi,

    Want to elaborate this statement in our case :

    PasteAndFormat Type:=wdFormatOriginalFormatting

    but we found the above codes may not be used (quite complicated to explain but the above codes affect "header" in each page of final word content, not really clear the reason at this moment)

    when we selection copy and paste onto another template in word 2010 in which this new file has header defined, if we adopt the above option, the header wording is changed (header font is changed and get bigger)

    If any expert know the possible cause, please kindly let me know.

    Thanks for your attention,

    Ray



    • Edited by RLee1010 Thursday, July 10, 2014 3:52 PM
    Thursday, July 10, 2014 3:41 PM
  • You can insert the content from another document, including all of its formatting with code as simple as:

    Dim DocSrc As Document, DocTgt As Document
    Set DocSrc = Documents.Open(FileName:="C:\Users\" & Environ("Username") & "Documents\Source.docx", _
      ReadOnly:=True, AddToRecenetFiles:=False)
    Set DocTgt = Documents.Open(FileName:="C:\Users\" & Environ("Username") & "Documents\Target.docx", _
      ReadOnly:=False, AddToRecenetFiles:=False)
    DocTgt.Range.Characters.Last.FormattedText = DocSrc.Range.FormattedText

    No copying/pasting involved. Of course, you don't have to transfer the entire document this way if you only want to transfer a portion. As for Style issues, you could use the Organizer to transfer the Style definitions. The possible issue you will have to deal with, though, concerns the use of the same Style name with differing definitions in the source files.


    Cheers
    Paul Edstein
    [MS MVP - Word]

    Friday, July 11, 2014 5:54 AM
  • Hi Ray

    If I'm following your problem description correctly the problem - the entire merged document takes on the font from the last file you process - this probably means that all three files use the same STYLE NAME. You'd need to ensure that each document uses different style names for the formatting. Then Word will import any style that a target document does not already use.

    This behavior is by design. The reasoning is that a combined document should usually appear as a single, integrated document with the same formatting for similar structures (body text, headings, etc.) throughout.


    Cindy Meister, VSTO/Word MVP, my blog

    Friday, July 11, 2014 3:29 PM
    Moderator