将模板中的图表插入MS Office应用程序 [英] Inserting charts from templates into MS Office applications

查看:135
本文介绍了将模板中的图表插入MS Office应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我已经定义了一组模板图表,我可以在MS Word和MS PowerPoint中查看和使用这些图表。


我要做的是开发一个将在PowerPoint中运行并从模板文件夹中插入特定图表的宏。每个图表模板的一个宏。


即使我尝试在MS Word中录制宏,它也显示为空。因为我不熟悉VBA,所以我正在努力解决这个问题。我尝试过一种非常基本的语法,例如:


Sub InsertChart()

  cht.ApplyChartTemplate RKChart1.crtx

End Sub


但是这找不到对象RKChart1.crtx,如果我从root输入完整路径仍然没有找到了吗?任何人都可以帮助我使用一些基本的宏语法来了解如何将模板图插入到PPT文件中吗?  


谢谢你,
罗宾

解决方案

嗨罗宾,


我用图表模板的全名在单词和电源点测试ApplyChartTemplate方法他们都运作良好。你使用全名还是完整路径?请问我在InsertChart子中显示整个代码?我会告诉你我的代码在power point中工作。你
可以尝试调整它并测试代码。

 Sub InsertChart()
Dim sld As Slide
Set sld = Application.ActivePresentation.Slides(1)
Dim shp As Shape
sld.Shapes.AddChart2类型:= xl3DLine
设置shp = sld.Shapes(1)
Dim ct As Chart
设置ct = shp.Chart
ct.ApplyChartTemplate" C:\ Users \Admin \Desktop \Charts\PPTPieChart.crtx"
结束子

问候,


Celeste



Hi,

I have defined a set of template charts, and these I can see and use in MS Word and MS PowerPoint.

What I am trying to do is develop a macro that will run in PowerPoint and insert a specific chart from the template folder. One macro for each chart template.

Even though I try to record a macro in MS Word, it appears empty. Because I am not familiar with VBA I am battling to get this resolved. I have tried a very basic syntax such as:

Sub InsertChart()
  cht.ApplyChartTemplate RKChart1.crtx
End Sub

But this does not find the object RKChart1.crtx and if I enter the full path from root is still doesn't find it? Can anyone help me with some basic macro syntax as to how I get a template graph inserted into a PPT file?  

Thanks
Robin

解决方案

Hi Robin,

I test ApplyChartTemplate method in word and power point with chart template's full name and they both work well. Did you use full name or full path? Could please show me whole code in your InsertChart sub? I will show you my code works in power point. You could try to adjust it and test the code.

Sub InsertChart ()
Dim sld As Slide
Set sld = Application.ActivePresentation.Slides(1)
Dim shp As Shape
sld.Shapes.AddChart2 Type:=xl3DLine
Set shp = sld.Shapes(1)
Dim ct As Chart
Set ct = shp.Chart
ct.ApplyChartTemplate "C:\Users\Admin\Desktop\Charts\PPTPieChart.crtx"
End Sub

Regards,

Celeste


这篇关于将模板中的图表插入MS Office应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆