Solved

SetShapesDefaultProperties (PowerPoint VBA) fails to set default line properties

Posted on 2013-05-27
3
2,570 Views
Last Modified: 2013-05-29
In PowerPoint 2010, trying to write a VBA macro to let the user enter a line with a pre-formatted style.  

I use the following method to do the same for shapes:  Create a dummy shape, set the shape fill color, line color, font size and color and style, etc., and finally use SetShapesDefaultProperties to store that as the default shape, then delete the dummy shape.  The next shape the user enters follows the saved style.   Works like a charm.  After running this, the next shape follows this style.

Dim myshp As Shape
Dim showingslide As Integer

showingslide = ActivePresentation.Windows(1).View.Slide.SlideIndex

Set myshp = ActivePresentation.Slides(showingslide).Shapes.AddShape(msoShapeRectangle, 10, 10, 10, 10)
With myshp
    .Fill.ForeColor.RGB = RGB(102, 0, 102)
    .Line.Visible = msoFalse
    .TextFrame.AutoSize = ppAutoSizeNone
    .TextFrame.TextRange.Font.Size = 18
    .TextFrame.VerticalAnchor = msoAnchorMiddle
    .TextFrame.TextRange.Font.Name = "Verdana"
    .TextFrame.TextRange.Font.Italic = msoFalse
    .TextFrame.TextRange.Font.Bold = msoFalse
    .TextFrame.TextRange.Font.Color.RGB = RGB(255, 255, 255)
    .SetShapesDefaultProperties
End With
myshp.Delete

Open in new window


HOWEVER, this does not seem to work for lines.   The following should set the default line to red, 1.75 thickness, with a triangular arrowhead.  

Dim myshp As Shape
Dim showingslide As Integer

showingslide = ActivePresentation.Windows(1).View.Slide.SlideIndex

Set myshp = ActivePresentation.Slides(showingslide).Shapes.AddShape(msoShapeLineInverse, 50, 50, 50, 50)
With myshp
    .Line.Visible = msoTrue
    .Line.Weight = 1.75
    .Line.ForeColor.RGB = RGB(255, 0, 0)
    .Line.EndArrowheadStyle = msoArrowheadTriangle
    .SetShapesDefaultProperties
End With
myshp.Delete

Open in new window


But even after running this macro, the next line I draw does NOT follow to the new style.   Am I doing something wrong?   Note that SetShapesDefaultProperties is equivalent to manually right-clicking a shape and choosing "Set as Default Shape."  For lines, the right-click option is "Set as Default Line" but for some reason there does not appear to be an equivalent VBA method for setting the default line.  

Can anybody help?
0
Comment
Question by:versatilebb
  • 2
3 Comments
 
LVL 23

Accepted Solution

by:
JSRWilson earned 500 total points
ID: 39202014
SetShapesDefaultProperties is contextual so it should work. I think you need to add a line though.

Sub LineDef()
Dim myshp As Shape
Dim showingslide As Long
showingslide = ActivePresentation.Windows(1).View.Slide.SlideIndex
Set myshp = ActivePresentation.Slides(showingslide).Shapes.AddLine(BeginX:=50, _
BeginY:=50,  _
EndX:=100,  _
EndY:=50)
With myshp
    .Line.Visible = msoTrue
    .Line.Weight = 1.75
    .Line.ForeColor.RGB = RGB(255, 0, 0)
    .Line.EndArrowheadStyle = msoArrowheadTriangle
    .Line.BeginArrowheadStyle = msoArrowheadDiamond
    .SetShapesDefaultProperties
End With
myshp.Delete
End Sub
0
 

Author Comment

by:versatilebb
ID: 39203391
Thanks, JSR.  

Using AddLine instead of AddShape seems to do the trick.  Default color and thickness are set as expected.  BeginArrowheadStyle works too, but for some reason EndArrowheadStyle does not seem to stick.  

Does it work for you?  Any thoughts on a solution?
0
 
LVL 23

Expert Comment

by:JSRWilson
ID: 39203780
Both start and end arrows work for me.

Screen Shot
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever been sent a PowerPoint presentation file and wondered why it filled your mailbox? Or have you ever sent a PowerPoint presentation by email and received complaints about the size? Or have you ever created a PowerPoint presentation and t…
Preface: When I started this series, I used the term CommandBars because that is the Office Object class that it discusses. Unfortunately, when Microsoft introduced Office 2007, they replaced the standard Commandbar menus with "The Ribbon" and rem…
The viewer will learn how to edit the master slide. They will also learn how to combine multiple themes into one master slide to use them in their presentation.
The viewer will learn how to edit text. This includes Font, Spacing, Resizing, Color, and other special text options.

785 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question