开发者

How to define a shape in Powerpoint using VBA?

It's a basic and easy question but no way to find the 开发者_开发技巧answer or a good tutorial in the web. And obviously no way to find it in this Office Help.

I'm using a macro in VBA to generate a Powerpoint. The code constists in copying a template slide of a Powerpoint Document assigning value of an Excelline into the defined shape of the PPT template.

The question is: I have no idea as to define the shape like in this previous code :

PptDoc.Slides(iSlide).Shapes("URL").TextFrame.TextRange = VerbatimSheet.Cells(i, 2).Value

How can I define the "url" shape? In the template or in the VBA Macro of Excel?


You can use índex of object for example

Dim shp as shape
Set shp=pptdoc.slides(islide).shapes(1)
shp.textframe.textrange= foo


In the ppt slide template, give your shape the name "URL" - not as easy to name shapes in ppt as in (eg) xl, but it can be done.

Just enter this in the immediate window of the ppt VB editor (with the shape selected) and hit enter:

ActiveWindow.Selection.shaperange(1).Name = "URL"

You can check it worked by entering:

? ActiveWindow.Selection.shaperange(1).Name 'should get "URL"


The two answers are correct and helps me a lot to understand this very basic step It's a great lesson for me thanks

The first code is the stylish way to get ride of the problem It has the advantage of defining by defaut a name to a shape and link it directly to the value I'm assigning to inside the code.

The second is a good way to help a beginner in programming but requires two macro. One in the Excel and one in the ppt and allow to change the name of the shapes manually. It has the advantage to help visualize exactly the shape you are using and you need to control.

Thank a lot to both of you!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜