1

I used https://www.brandwares.com/bestpractices/2015/06/xml-hacking-custom-colors/ to create custom colors in PowerPoint using VBA.

I want to know how to access these custom colors and create a colorized table in PowerPoint where a cell is colored by the corresponding custom color and the hex value is written in the cell. Thank you in advance.

luke
  • 25
  • 7
  • Please post your code and we'll help you debug it. – John Korchok Jun 19 '23 at 01:14
  • The challenge begins with "which ist the object" to refer to. – luke Jun 21 '23 at 03:14
  • In a test presentation, you might start with _ActiveWindow.Selection.Shaperange(1).Table_. A search using the terms _powerpoint vba set table cell color_ gets sample code. – John Korchok Jun 21 '23 at 14:27
  • The table and the cell coloring is not the challenge; the challenge remains for me how to access the "custom color" schema. – luke Jun 22 '23 at 05:39
  • As I requested previously, please post your code. – John Korchok Jun 22 '23 at 15:02
  • I tried and find the Custom colors through VBA but they seem hidden from view. You could use XSLT to isolate them (here a sample about extracting values https://stackoverflow.com/questions/23647439/extracting-values-from-xml-file-using-xslt) and here on how to call it from VBA https://stackoverflow.com/questions/42309079/transforming-xml-using-an-xslt, then convert them https://exceloffthegrid.com/convert-color-codes/ – Oran G. Utan Jun 22 '23 at 15:53

1 Answers1

0

The below will create an array of the custom colors present in a theme file, then the values can be stored somewhere. A similar approach can be used to add the colors, instead.

Please note that, in order to use it, you will have to:

  • change the extension of the presentation to .zip (and click "Yes" at the prompt)
  • enter the zipped file and take the file(s) .zip\ppt\theme, pasting them somewhere else
  • Process them as needed
  • Put them back (not your case unless you want to modify the colors or something else)

Sub ListPowerPointCustomCoLorsV2()

Dim sL As Slide: Set sL = ActivePresentation.Slides(1)
Dim xLAppL As Excel.Application: Set xLAppL = GetObject(, "Excel.Application")
Dim wBTrgt As Excel.Workbook: Set wBTrgt = xLAppL.ActiveWorkbook
Dim oXMLFile As Object: Set oXMLFile = CreateObject("Microsoft.XMLDOM")
Dim XMLFileName As String: XMLFileName = xLAppL.GetOpenFilename(Title:="Please choose XML-file with Load Case definitions", FileFilter:="XML Files *.xml (*.xml),")



oXMLFile.Load (XMLFileName)

Dim tHeme_BLock As MSXML2.IXMLDOMElement: Set tHeme_BLock = oXMLFile.SelectSingleNode("a:theme")
Dim tHeme_BLock_CustomCoLors As MSXML2.IXMLDOMElement: Set tHeme_BLock_CustomCoLors = tHeme_BLock.ChildNodes(3)

Dim customCoLor_XmL() As String: ReDim customCoLor_XmL(1 To tHeme_BLock_CustomCoLors.ChildNodes.Length, 1 To 2) 'customCoLor_XmL_XmL.ChildNodes.Length, 1 To 2)

Dim tHeme_ChiLd_Count As Long

For tHeme_ChiLd_Count = 1 To UBound(customCoLor_XmL) 'tHeme_BLock.ChildNodes.Length

    Dim tHeme_CurrentCoLor As MSXML2.IXMLDOMElement
    Set tHeme_CurrentCoLor = tHeme_BLock_CustomCoLors.ChildNodes(tHeme_ChiLd_Count - 1)
    
    customCoLor_XmL(tHeme_ChiLd_Count, 1) = tHeme_CurrentCoLor.ChildNodes(0).Attributes(0).Text
    customCoLor_XmL(tHeme_ChiLd_Count, 2) = tHeme_CurrentCoLor.Attributes(0).Text

Next tHeme_ChiLd_Count

'Do something with array

oXMLFile.Save (XMLFileName)

End Sub

enter image description here

Oran G. Utan
  • 455
  • 1
  • 2
  • 10