none
PPT VSTO set font colour based on stored color variable RRS feed

  • Question

  • Hi All,

    Building some buttons for a custom ribbon tab and we have some pre-set colours stored. Trying to write code to set font colour based on stored variables e.g. to test this out using the standard purple and orange, I have some global variables:

    Public ReadOnly Colours_Purple As Color = Color.FromArgb(112, 48, 160)
    Public ReadOnly Colours_Orange As Color = Color.FromArgb(255, 192, 0)

    I then have a sub that has

    Dim ColourChoice As Drawing.Color

            Select Case ChooseColour
                Case "Purple"
                    ColourChoice = Colours_Purple           

               Case "Orange"
                    ColourChoice = Colours_Orange

    Etc

    And I'm then trying to use it like this:


    Globals.ThisAddIn.Application.ActiveWindow.Selection.TextRange.Font.Color = ColourChoice

    But get error that 'color' is read only.

    All alternatives I can find such as at the link below require specifying the RBG code in the line of code though this is not efficient for the possibility of wanting the change the RGB codes only once.

    https://stackoverflow.com/questions/5247135/how-can-i-change-the-font-color-of-a-textrange-in-powerpoint-from-c

    How do I set colour of selected text using a color variable?

    Monday, July 2, 2018 1:10 PM

All replies

  • Hello cptjonkinbllll,

    Please try,

    Dim objSelection As PPT.Selection
            objSelection = Globals.ThisAddIn.Application.ActiveWindow.Selection
            Dim objFont As Object
            If objSelection.Type = PPT.PpSelectionType.ppSelectionShapes Then
                objFont = objSelection.ShapeRange.Item(1).TextFrame.TextRange.Font
                objFont.Color.RGB = Colours_Purple.ToArgb
            Else
                MsgBox("Your select item does not contain any shape")
            End If

    Best Regards,

    Terry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, July 3, 2018 2:53 AM
  • Hello cptjonkibllll,

    What's the current state of the thread? If your issue has been solved, I would suggest you mark helpful reply to close the thread or provide your solution and mark it to help more people who runs into the same issue.

    If not, please feel free to let us know if you have any updates for your issue.

    Best Regards,

    Terry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, July 6, 2018 7:14 AM