Solved

SetShapesDefaultProperties (PowerPoint VBA) fails to set default line properties

Posted on 2013-05-27
3
2,656 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:Bryce Bassett
[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:Bryce Bassett
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

This article describes how to make a simple, pseudo-random number generator in Microsoft PowerPoint. The code checks the generated numbers against a list of numbers already generated to prevent duplication. We used this as a youth group activity but…
Setting the Scene Animations in PowerPoint are a great tool to convey messages when used carefuly with the content of your slides. There are plenty of animation effects and options, including a Repeat feature for individual animation effects. …
This video teaches viewers how to create handouts from their slides and helps them decide how many slides to include per handout.
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.

628 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