How to change the font color of a text DataObject when is is pasted RRS feed

  • Question

  • I'm building an application in Excell vba, but this is a more general question.

    The application takes spreadsheet values and configures them in a text box to be pasted on another document.

    (The other document is an engineering drawing with dimensions that we "mark-up" with the calculated values. The existing drawing has dimensions in black.)

    The text to be pasted is in a DataObject built as follows:

    Dim DimSet As New DataObject
    DimSet.SetText txtDim.Text

     When we paste the dimension set on the existing drawing, I'd like the font color to be red, so that the markup is distinguishable from existing text on the drawing.

    Can Excell vba access an OnPaste event?  Or is there a better way to accomplish this?


    Saturday, September 14, 2013 7:43 PM


  • This question is not related to Excel. If the destination application is not able to handle additional informations when you paste something from the clipboard, you can do whatever you want in Excel.

    Anyway, the DataObject only provides just text, no colors or something else. But you can have a (hidden) sheet form temporary operations (or use a special cells in an existing sheet, doesn't matter).

    If the text is ready in txtDim, write it into a cell, format that cell as you like (red color, italic font, etc.) and use the Copy method to get all the informations of the cell into the clipboard. (Excel writes many different data types into the clipboard when you just call Copy).

    Then switch to your application and paste the clipboard into the drawing and look what happens.


    PS.: I'm on vacation the next 3 weeks, an answer may take a while.

    Sunday, September 15, 2013 8:19 AM