1

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 ?

Thomas C.
  • 217
  • 1
  • 12
  • 2
    Your two methods return two different things. In the first case, you're getting the name of the theme of the current presentation. In the second, you're removing the path from the full name of an already-known theme file, aren't you? In any case, to answer your question, I'd use the first method, but use Set pptPres = Presentations.Open("your filename",true,,false) That will open the presentation windowlessly, which speeds things up considerably. Don't forget to use pptPres.Close after you're done with it. – Steve Rindsberg Aug 15 '22 at 15:27
  • @SteveRindsberg, indeed yes. 1st method opens the theme file as a presentation which creates a new presentation that uses the theme. I then retrieve the theme name using the .TemplateName method. Anyway thanks for your advices :) – Thomas C. Aug 16 '22 at 07:23
  • 1
    My apologies. I misunderstood your question. Thanks for correcting me. In that case, since you know the path to the theme file, parsing the filename will be considerably faster (ie method 2) – Steve Rindsberg Aug 16 '22 at 13:51

0 Answers0