Solved

SetShapesDefaultProperties (PowerPoint VBA) fails to set default line properties

Posted on 2013-05-27
3
2,619 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

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…
Many programs have tried to outwit PowerPoint in terms of technology and skill. These programs, however, still lack several characteristics that PowerPoint has possessed from the start. Here's why PowerPoint replacements won't entirely work for desi…
This video teaches viewers how to add transitions to their Slideshows and how to set up timing for the transitions.
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.

734 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