View Single Post
 
Old 04-12-2025, 07:32 AM
gmayor's Avatar
gmayor gmayor is offline Windows 10 Office 2019
Expert
 
Join Date: Aug 2014
Posts: 4,142
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

Surely the format painter would be more appropriate for this task? However, the following should work.
Code:
Sub ColorRGBText()
Dim myColor As String
Dim OPT As Long
Dim MyData As DataObject
    Set MyData = New DataObject
    OPT = InputBox("Get Color[1], Apply Color[2]", "Color Management", "1")
    If OPT = 1 Then
        'MsgBox Selection.Font.TextColor.RGB
        myColor = Selection.Font.TextColor 'gets the color`
        MyData.SetText myColor
        MyData.PutInClipboard 'copies color code into ClBrd
    End If
    'When the macro is restarted and option 2 selected, the color code should be applied to a different text selection
    If OPT = 2 Then
        MyData.GetFromClipboard
        myColor = MyData.GetText(1)
        If myColor <> "" Then
            Selection.Font.TextColor = myColor
        Else
            MsgBox "Color has not been selected"
        End If
    End If
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote