none
Copy pasting code from VS2010 to Word 2010 RRS feed

  • Question

  • I'm trying to paste some code from Visual Studio 2010 to Word 2010 (over remote) but it doesn't keep neither the formatting or the colors.

    I even tried pasting to Notepad++ on my machine, selecting the appropriate language that colors it, using the "Copy with Syntax Highlighting" plugin function and when I paste into word it's still not formatted, default font black code snippet.



    What is wrong here, how do I make this work?
    Saturday, August 11, 2012 1:15 PM

Answers

  • Hi ZaneRes,

    Thanks for posting in the MSDN Forum.

    I never see the scenario which your mentioned. It will keep the format.

    Please try following snippet, it works fine on my side.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Microsoft.Office.Tools.Ribbon;
    using Word = Microsoft.Office.Interop.Word;
    
    namespace WordAddIn2
    {
        public partial class Ribbon1
        {
            private void Ribbon1_Load(object sender, RibbonUIEventArgs e)
            {
    
            }
    
            private void button1_Click(object sender, RibbonControlEventArgs e)
            {
                Word.Document doc = Globals.ThisAddIn.Application.ActiveDocument;
                Word.Range rang = doc.Range();
                rang.PasteSpecial();
            }
        }
    }

    Have a good day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us

    Monday, August 13, 2012 6:26 AM
    Moderator