I am writing a code that runs in Excel that needs to retrieve the name of Microsoft Office Theme (i.e. PowerPoint theme/template, .thmx file), only knowing its file path.
I have found two ways to retrieve the name :
- Method 1 : Using Presentation.TemplateName
Opens the theme file as a presentation which creates a new presentation that uses this theme. I then retrieve the theme name using Presentation.TemplateName method
Sub test3()
Dim pptApp As New PowerPoint.Application
Dim pptPres As Presentation
Dim themeName As String
On Error Resume Next
Set pptPres = pptApp.Presentations.Open("C:\Users\...\...\Document Themes\Template STQ DABS.thmx")
themeName = pptPres.TemplateName
End Sub
- Method 2 : Using Split
Removes the path and extension of the theme full name (file path) to retrieve its name
Sub test4()
Dim themePath, fileName, themeName As String
themePath = "C:\Users\...\...\Document Themes\Template STQ DABS.thmx"
fileName = Split(themePath, "\")(UBound(Split(themePath, "\"))) ' get rid of folder path
themeName = Split(fileName, ".")(LBound(Split(fileName, "."))) ' get rid of extension
End Sub
Although these 2 methods works, is there a cleaner way to retrieve the name of a PowerPoint Theme ?