Solved

SetShapesDefaultProperties (PowerPoint VBA) fails to set default line properties

Posted on 2013-05-27
3
2,523 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

 Regular Expressions Microsoft Word has sophisticated search tools that can search for patterns. For example if you wanted to search for all UK phone numbers that followed a pattern of five digits, a space and then six digits you can easily do th…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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.

757 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now