+ Reply to Thread
Results 1 to 9 of 9

Trying to edit colored text using VBA without losing my different colors upon edit

Hybrid View

pglufkin Trying to edit colored text... 06-26-2012, 01:35 PM
rvasquez Re: Trying to edit colored... 06-26-2012, 01:46 PM
pglufkin Re: Trying to edit colored... 06-26-2012, 02:22 PM
rvasquez Re: Trying to edit colored... 06-26-2012, 02:47 PM
pglufkin Re: Trying to edit colored... 06-26-2012, 03:08 PM
pglufkin Re: Trying to edit colored... 06-26-2012, 08:26 PM
rvasquez Re: Trying to edit colored... 06-27-2012, 10:29 AM
pglufkin Re: Trying to edit colored... 06-27-2012, 12:55 PM
rvasquez Re: Trying to edit colored... 06-27-2012, 02:50 PM
  1. #1
    Registered User
    Join Date
    06-19-2005
    Posts
    49

    Trying to edit colored text using VBA without losing my different colors upon edit

    Trying to create a macro which will add additional text to existing text in a cell, at the beginning of the cell and does not remove the different colors found in the original text upon edit. Was trying this command:

    ActiveCell = "String" & ActiveCell

    But when I use this, all the different color formatting in my cell goes away upon execution of the edit.

    Is there a SendKeys approach I can use such as Edit, go to first part of the cell, and SendKey five spaces?

    In line with this, I tried this as an attempted work around:

    Application.SendKeys ("{F2}")
    Application.SendKeys ("^{Home}")
    Application.SendKeys ("Inserted Text")
    Application.SendKeys ("Enter")

    But it does nothing.

    thank you

  2. #2
    Valued Forum Contributor
    Join Date
    03-23-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    1,093

    Re: Trying to edit colored text using VBA without losing my different colors upon edit

    Hello there,

    If I understood you correctly you just want a macro that when selected will add a string to the beginning of the cell? If this is correct then I think this will accomplish what you are trying to do.

    While holding down the Alt key your keyboard press F8. This will bring up the Macro window. In the macro name space provided, clear the contents and the type AddString. Then select the Create option.

    In between the lines of code
    Sub AddString
    and
    End Sub
    paste the following

    Dim str As String  'declare variables
        str = ActiveCell.Value  'set the variable str equal to the active cell's value
        ActiveCell.Value = "YourTextHere" & "    " & str  'active cell's value is now equal to the text YourTextHere and what was orginally in the activecell
    So the entire code should look like this

    Sub AddString()
        
    Dim str As String
        str = ActiveCell.Value
        ActiveCell.Value = "YourTextHere" & "    " & str
        
    End Sub
    Close the VBA Window and to run it select the cell you wish to alter press Alt+F8 again then select the AddString Macro and select run.

    Let me know if this works!

    Thanks!

  3. #3
    Registered User
    Join Date
    06-19-2005
    Posts
    49

    Re: Trying to edit colored text using VBA without losing my different colors upon edit

    Hi, thanks for trying. This is the same as my other solutions . . . it does not work. When the macro executes, I lose all the different colors in my text. My text is multi-colored and I want to keep it multicolored. When I execute your macro, all the color becomes mono-colored. This is why i think a send keys edit solution is the way, because when I manually add text, the colors remain.

  4. #4
    Valued Forum Contributor
    Join Date
    03-23-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    1,093

    Re: Trying to edit colored text using VBA without losing my different colors upon edit

    Could you post a sample of your workbook? Thanks!

  5. #5
    Registered User
    Join Date
    06-19-2005
    Posts
    49

    Re: Trying to edit colored text using VBA without losing my different colors upon edit

    Sure, thx.
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    06-19-2005
    Posts
    49

    Re: Trying to edit colored text using VBA without losing my different colors upon edit

    Anyone else want to try?

  7. #7
    Valued Forum Contributor
    Join Date
    03-23-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    1,093

    Re: Trying to edit colored text using VBA without losing my different colors upon edit

    Do the colors of the text stay the same or do they change?

  8. #8
    Registered User
    Join Date
    06-19-2005
    Posts
    49

    Re: Trying to edit colored text using VBA without losing my different colors upon edit

    They need to stay the same. After I run a macro adding text to the string, i am not concerned about the text color that I add, just that the text that I add to does not lose its coloring. Thx.
    Last edited by pglufkin; 06-27-2012 at 12:57 PM.

  9. #9
    Valued Forum Contributor
    Join Date
    03-23-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    1,093

    Re: Trying to edit colored text using VBA without losing my different colors upon edit

    Hey there, alright this seems like a lot so if someone knows another way to do it or if it doesn't work for you let me know. I inserted comments that will help you understand.

    Let me know if it works for you.
    Attached Files Attached Files

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1