首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >带有通用路径文件的Excel VBA Mypresentation.ApplyTemplate

带有通用路径文件的Excel VBA Mypresentation.ApplyTemplate
EN

Stack Overflow用户
提问于 2016-06-23 12:54:43
回答 2查看 589关注 0票数 1

我想使用模板将数据从EXCEL复制到EXCEL的POWERPOINT演示文稿中。当我使用显式路径时,它会工作。但是,我想使用一个相对路径来运行它,但是它会抛出以下错误

代码语言:javascript
复制
Sub PowerPoint()

Dim rng As Excel.Range
Dim PowerPointApp As PowerPoint.Application
Dim myPresentation As PowerPoint.Presentation
Dim mySlide As PowerPoint.Slide
Dim myShapeRange As PowerPoint.Shape
Dim Template As String




'Copy Range from Excel
  Set rng = Worksheets("Contact Page").Range("C2:O38")


'Create an Instance of PowerPoint
  On Error Resume Next

    'Is PowerPoint already opened?
      Set PowerPointApp = GetObject(class:="PowerPoint.Application")

    'Clear the error between errors
      Err.Clear

    'If PowerPoint is not already open then open PowerPoint
      If PowerPointApp Is Nothing Then Set PowerPointApp = CreateObject(class:="PowerPoint.Application")

    'Handle if the PowerPoint Application is not found
      If Err.Number = 429 Then
        MsgBox "PowerPoint could not be found, aborting."
        Exit Sub
      End If

  On Error GoTo 0

'Make PowerPoint Visible and Active
  PowerPointApp.Visible = True
  PowerPointApp.Activate

'Create a New Presentation

  Template = CurDir()
  Template = Template & "\TEMPLATE3.potm"
  Set myPresentation = PowerPointApp.Presentations.Add
   myPresentation.ApplyTemplate (Template)
  'myPresentation.ApplyTemplate ("C:\Users\Oriol\Documents\3mundi\Reporting\BR\New Model\TEMPLATE3.potm")
  myPresentation.PageSetup.SlideSize = ppSlideSizeOnScreen

错误

我该怎么办?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2016-06-23 13:02:46

假设模板文件位于Excel文件的同一个文件夹中,则更改语句:

代码语言:javascript
复制
Template = CurDir()

至:

代码语言:javascript
复制
Template = ThisWorkbook.Path
票数 1
EN

Stack Overflow用户

发布于 2016-06-23 13:15:09

Excel文件是否与您的文件夹位于相同的位置?CurDir()返回当前保存excel文件的路径。因此,如果您的文件夹保存在子文件夹中,您也需要在路径中使用该子文件夹:

代码语言:javascript
复制
Template = CurDir()
Template = Template & "\SubFolder\TEMPLATE3.potm"
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37992271

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档