使用VBA将PowerPoint主题设置为默认值

时间:2014-02-05 15:05:13

标签: excel vba excel-vba powerpoint powerpoint-vba

我无法在任何地方找到使用Excel VBA或PowerPoint(2010)VBA将PowerPoint主题设置为默认主题的语法。

为了澄清我正在尝试做什么,手动执行此操作的步骤是:转到PowerPoint中的设计选项卡,右键单击所需主题并选择“设为默认值”选项。此过程设置默认主题和幻灯片主默认值。

下面的语法将设置主题(使用Excel VBA)一次,但不会将主题设置为默认主题。如何将主题设置为新默认值?

Set PPApp = CreateObject("Powerpoint.Application") 
PPApp.Visible=True                                                                                              
Set PPPres = PPApp.Presentations.Add                   
PPPres.ApplyTemplate ("Location")

非常感谢David提出以下想法,但不幸的是,它们并不适用于我的预期应用程序。我正在尝试创建一个宏,它将在打开时设置默认主题,以便我可以将该文件分发到我的组织并控制我们正在处理的幻灯片模板。发现此HERE的宏非常接近,但我找不到将锁定在应用模板中的语法。想法?

Sub AutoOpen()
    Dim ThemePath As String
    Dim ThemeFile As String
    Dim FullPath As String

    ActivePresentation.PageSetup.SlideSize = ppSlideSizeOnScreen16x9

    ThemeFile = "TestTemplate.potx"
    ThemePath = "File Path"
    FullPath = ThemePath + ThemeFile

    On Error Resume Next
        ActivePresentation.ApplyTemplate (FullPath)
    If Err <> 0 Then
        MsgBox (ThemeFile & " was not found in " & ThemePath)
    End If
End Sub 

1 个答案:

答案 0 :(得分:0)

我知道这已经太晚了4年,但我不认为这个问题得到了充分的回答。在上面的代码中,您应该将以下字符串变量设置为:

ThemeFile = "blank.potx" '(it has to be "blank" or else it won't work)
ThemePath = "C:\Users\" vba.environ("username") & "\AppData\Roaming\Microsoft\Templates"

http://youpresent.co.uk/set-the-default-template-when-powerpoint-starts/