首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在所有PPT图表上应用模板将导致“用户定义类型未定义”错误。

在所有PPT图表上应用模板将导致“用户定义类型未定义”错误。
EN

Stack Overflow用户
提问于 2019-01-19 12:40:06
回答 2查看 198关注 0票数 0

我试图在我的PPT中的所有图表上应用一个模板,但是得到一个错误声明

未定义用户定义类型

我在网上找到了VBA,分享它的人说它对他有用。有什么建议吗?我认为这可能是路径上的破折号,但使用"-“或"_”没有帮助。还试着移除路径之后的最后一个括号。

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

    Dim myChart As ChartObject
    For Each myChart In ActiveSheet.ChartObjects
    myChart.Chart.ApplyChartTemplate ( _
    "Name\Users\Name\Library\Group Containers\UBF8T346G9.Office\User Content\Chart Templates\1.crtx")
    Next myChart

End Sub

新VBA尝试;

代码语言:javascript
复制
Sub ChangeCharts()
  Dim oSl As Slide
  Dim oSh As Shape

  For Each oSl In ActivePresentation.Slides
    For Each oSh In oSl.Shapes
      Select Case oSh.Type
        Case Is = 3  ' Chart created in PPT
        Application.ActivePresentation.ApplyTemplate _
    "name/Users/name/Library/Group Containers/UBF8T346G9.Office/User Content/Chart Templates/1.crtx"

      End Select
    Next   ' oSh/Shape
  Next  ' oSl/Slide
End Sub
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2019-01-19 18:16:31

首先,请参阅下面的注释,了解为什么示例代码不能在PPT中工作:

代码语言:javascript
复制
Sub ChangeCharts()
    ' PPT has no ChartObject type  
    Dim myChart As ChartObject
    ' PPT has no ActiveSheet object
    For Each myChart In ActiveSheet.ChartObjects
    myChart.Chart.ApplyChartTemplate ( _
    "Name\Users\Name\Library\Group Containers\UBF8T346G9.Office\User Content\Chart Templates\1.crtx")
    Next myChart

End Sub

假设您在PPT内部运行这个程序,您将需要更多类似的内容:

代码语言:javascript
复制
Sub ChangeCharts
  Dim oSl as Slide
  Dim oSh as Shape

  For Each oSl in ActivePresentation.Slides
    For Each oSh in oSl.Shapes
      Select Case oSh.Type
        Case Is = 3  ' Chart created in PPT
          ' apply the template here
          With oSh.Chart
            .ApplyChartTemplate "drive:\path\template_name.crtx"
          End with  ' the chart
        ' Other case statements as needed to
        ' cover embedded/linked OLE objects 
        ' that are Excel charts
      End Select
    Next   ' oSh/Shape
  Next  ' oSl/Slide
End Sub
票数 0
EN

Stack Overflow用户

发布于 2019-01-19 12:50:39

ActiveSheet是一个Excel对象。我认为您想使用ActiveSlide来实现PowerPoint。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54267188

复制
相关文章

相似问题

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