Solved

SetShapesDefaultProperties (PowerPoint VBA) fails to set default line properties

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

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

People often ask "How do I make this macro run every time I show a new slide or add a new slide etc." This means making PowerPoint respond to that EVENT and, unlike in Excel, it's not that easy! First, I would avoid using the pseudo events left o…
Technology opened people to different means of presenting information, but PowerPoint remains to be above competition. Know why PPT still works today.
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  create a slide that will launch other presentations in Microsoft PowerPoint. In the finished slide, each item launches a new PowerPoint presentation and when each is finished it automatically comes back to this slide: …

820 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