VBA Express Forum  




Go Back   VBA Express Forum > VBA Code & Other Help > PowerPoint Help
     Feedback     
Register FAQ Members Arcade Knowledge Base Training Articles Consulting

Reply
 
Thread Tools Display Modes
Old 04-10-2012, 10:21 AM   #1
elunicotomas

 
Joined: Apr 2012
Posts: 6
Kb Entries: 0
Articles: 0
Create a shape with a predefined format?

Hi there, Im trying to create a macro that paste "flags" (shapes of different colors) to clasify the slides of a presentation.

I´m totally new to VBA. I managed to create a rectangular shape in the TOP RIGHT corner of the current slide, but it create a blue shape with blue border, and i want this shape to be red, 35% transparency and no border.

Is there any way to pre-define the format of the shape before creating it? or should I change the shape´s format once it´s created?

Thanks!

VBA:
Sub AZ_Banderitas() 'if there´s no slide selected the shape will be pasted in the previous slide On Error Resume Next Err.Clear Debug.Print "The current slide is Slide " & ActiveWindow.View.Slide.SlideIndex If Err <> 0 Then ActiveWindow.ViewType = ppViewNotesPage ActiveWindow.ViewType = ppViewNormal Debug.Print "The current slide is Slide " & ActiveWindow.View.Slide.SlideIndex End If 'creates shape slideLocation = ActiveWindow.View.Slide.SlideIndex myDocument.Shapes.AddShape Type:=msoShapeRectangle, Left:=570, Top:=0, width:=150, Height:=100 End Sub
VBA tags courtesy of www.thecodenet.com

Local Time: 08:29 AM
Local Date: 05-24-2013
Location:

 
Reply With Quote Top
Old 04-10-2012, 10:48 AM   #2
elunicotomas

 
Joined: Apr 2012
Posts: 6
Kb Entries: 0
Articles: 0
I´ve changed the code a bit..

VBA:
Sub AZ_Banderitas() 'if there´s no slide selected the shape will be pasted in the previous slide On Error Resume Next Err.Clear Debug.Print "The current slide is Slide " & ActiveWindow.View.Slide.SlideIndex If Err <> 0 Then ActiveWindow.ViewType = ppViewNotesPage ActiveWindow.ViewType = ppViewNormal Debug.Print "The current slide is Slide " & ActiveWindow.View.Slide.SlideIndex End If 'creates shape slideLocation = ActiveWindow.View.Slide.SlideIndex Set myDocument = ActivePresentation.Slides(slideLocation) Dim shp As Shape Set shp = myDocument.Shapes.AddShape(msoShapeRectangle, 570, 0, 150, 100) End Sub
VBA tags courtesy of www.thecodenet.com

Local Time: 08:29 AM
Local Date: 05-24-2013
Location:

 
Reply With Quote Top
Old 04-10-2012, 03:39 PM   #3
Cosmo

 
Joined: May 2008
Posts: 185
Kb Entries: 0
Articles: 0
Creating a new shape will use the default properties for that shape. If you want it to always be a certain color (or change any other property) when you run the code, then you should set the properties after creating it.
VBA:
Dim shp As Shape Set shp = myDocument.Shapes.AddShape(msoShapeRectangle, 570, 0, 150, 100) shp.Fill.ForeColor.RGB = RGB(255, 0, 0)
VBA tags courtesy of www.thecodenet.com

If you have multiple properties you can set them like this:
VBA:
Dim shp As Shape Set shp = myDocument.Shapes.AddShape(msoShapeRectangle, 570, 0, 150, 100) With shp .Fill.ForeColor.RGB = RGB(255, 0, 0) .Height = 200 '... and any other properties here End With
VBA tags courtesy of www.thecodenet.com


Otherwise, your script will always use whatever are set as the default shape properties when the script runs.

Local Time: 07:29 AM
Local Date: 05-24-2013
Location:

 
Reply With Quote Top
Old 04-11-2012, 08:50 AM   #4
elunicotomas

 
Joined: Apr 2012
Posts: 6
Kb Entries: 0
Articles: 0
Quote:
 
Originally Posted by: Cosmo
Creating a new shape will use the default properties for that shape. If you want it to always be a certain color (or change any other property) when you run the code, then you should set the properties after creating it.
VBA:
Dim shp As Shape Set shp = myDocument.Shapes.AddShape(msoShapeRectangle, 570, 0, 150, 100) shp.Fill.ForeColor.RGB = RGB(255, 0, 0)
VBA tags courtesy of www.thecodenet.com

If you have multiple properties you can set them like this:
VBA:
Dim shp As Shape Set shp = myDocument.Shapes.AddShape(msoShapeRectangle, 570, 0, 150, 100) With shp .Fill.ForeColor.RGB = RGB(255, 0, 0) .Height = 200 '... and any other properties here End With
VBA tags courtesy of www.thecodenet.com


Otherwise, your script will always use whatever are set as the default shape properties when the script runs.


Thanks! That worked, now im trying to put some text in those boxes...

VBA:
Set myDocument = ActivePresentation.Slides(slideLocation) Dim shp As Shape Set shp = myDocument.Shapes.AddShape(msoShapeRectangle, 570, 0, 150, 100) With shp.Fill .Transparency = 0.35 .Visible = msoTrue .ForeColor.RGB = RGB(255, 0, 0) .Solid End With With shp.Line .Visible = msoFalse End With
VBA tags courtesy of www.thecodenet.com

Local Time: 08:29 AM
Local Date: 05-24-2013
Location:

 
Reply With Quote Top
Old 04-11-2012, 10:04 AM   #5
Cosmo

 
Joined: May 2008
Posts: 185
Kb Entries: 0
Articles: 0
VBA:
shp.TextFrame.TextRange.Text = "Enter your text here"
VBA tags courtesy of www.thecodenet.com

Local Time: 07:29 AM
Local Date: 05-24-2013
Location:

 
Reply With Quote Top
Old 04-11-2012, 11:27 AM   #6
elunicotomas

 
Joined: Apr 2012
Posts: 6
Kb Entries: 0
Articles: 0
Quote:
 
Originally Posted by: Cosmo
VBA:
shp.TextFrame.TextRange.Text = "Enter your text here"
VBA tags courtesy of www.thecodenet.com


Thanks again!

Local Time: 08:29 AM
Local Date: 05-24-2013
Location:

 
Reply With Quote Top
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -7. The time now is 04:29 AM.


Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Copyright © 2004 - 2012 VBA Express