我试图在我的PPT中的所有图表上应用一个模板,但是得到一个错误声明
未定义用户定义类型
我在网上找到了VBA,分享它的人说它对他有用。有什么建议吗?我认为这可能是路径上的破折号,但使用"-“或"_”没有帮助。还试着移除路径之后的最后一个括号。
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尝试;
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发布于 2019-01-19 18:16:31
首先,请参阅下面的注释,了解为什么示例代码不能在PPT中工作:
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内部运行这个程序,您将需要更多类似的内容:
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发布于 2019-01-19 12:50:39
ActiveSheet是一个Excel对象。我认为您想使用ActiveSlide来实现PowerPoint。
https://stackoverflow.com/questions/54267188
复制相似问题