繁体   English   中英

如何通过VBA使用Powerpoint模板来构建所需的幻灯片?

[英]How do I use my powerpoint template through VBA in order to build my desired slides?

我无法弄清楚如何将模板合并到VBA中的实际代码中,以便将工作表构建在所需的模板和幻灯片中。

我已经在新的空白PowerPoint幻灯片中构建了幻灯片,但还无法弄清楚如何使用模板。

Sub LCTAKT_Macro()
    'Declare variables
    Dim PP As PowerPoint.Application
    Dim PPPres As PowerPoint.Presentation
    Dim PPSlide1 As PowerPoint.Slide
    Dim PPSlide2 As PowerPoint.Slide
    Dim PPSlide3 As PowerPoint.Slide
    Dim PPSlide4 As PowerPoint.Slide
    Dim PPSlide5 As PowerPoint.Slide
    Dim PPSlide6 As PowerPoint.Slide
    Dim PPSlide7 As PowerPoint.Slide
    Dim SlideTitle As String
    Dim objPPT As Object

    'Open PowerPoint and create new presentation
    Set objPPT = CreateObject("PowerPoint.Application")
    objPPT.Visible = True

    Set PP = New PowerPoint.Application
    Set PPPres = PP.Presentations.Add
    PP.Visible = True

    objPPT.Presentations.Open ""

    '-------------------------------------------------Station 42---------        ------------------------------------------------
    'Add new slide as slide 2 and set focus to it
    Set PPSlide1 = PPPres.Slides.Add(1, ppLayoutTitleOnly)
    PPSlide1.Select

    'Copy the range as a picture
    Sheets("").Range("A1:W59").CopyPicture _
    Appearance:=xlScreen, Format:=xlPicture

    'Paste the picture and adjust its position
    PPSlide1.Shapes.Paste.Select
    PP.ActiveWindow.Selection.ShapeRange.Align msoAlignCenters, True
    PP.ActiveWindow.Selection.ShapeRange.Align msoAlignMiddles, True

    'Add the title to the slide
    SlideTitle = ""
    PPSlide1.Shapes.Title.TextFrame.TextRange.Text = SlideTitle

    'Position pasted chart
    PP.ActiveWindow.Selection.ShapeRange.Left = 200
    PP.ActiveWindow.Selection.ShapeRange.Top = 130
    PP.ActiveWindow.Selection.ShapeRange.Height = 523
    PP.ActiveWindow.Selection.ShapeRange.Width = 554

我希望模板可以包含在幻灯片中,同时仍为其构建必要的数据片段。

假设Office 2013或更高版本,请尝试以下操作:

TemplateName$ = "C:\Users\YourActualUserName\Documents\Custom Office Templates\YourActualTemplateName.potx"
Set PPPres = PP.Presentations.Open(TemplateName$, False, True, True)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM