View Full Version : Solved: "Library" of formatted shapes
Paul_Hossler
01-10-2009, 06:38 PM
Looking for a VBA, non-VBA, or manual technique to pick and apply a shape, including it's formatting.
For ex. I might have an
a. oval shape, no fill, red, 3pt lines that I use to circle words, etc. on a slide,
b. a star shape with text to flag an important topic, and
c. a button with specific formatting
I typically use a small number of these identical shapes many times in a presentation
Right now, I either insert and reapply all formatting, or copy and paste from an already formatted shape (maybe change the text) AFTER I scroll back and forth in the presentation to find it.
It's be really nice if there were a "palette" of formatted shapes that I could always get to to copy and paste.
Out of the box thinking is OK:rotlaugh:
Paul
John Wilson
01-12-2009, 11:23 AM
Two ways spring to mind
Write an addin that creates a menu to call macros to add shapes to the current slide:
eg code to add your oval
Sub addshape()
Dim osld As Slide
Dim oshp As Shape
Set osld = ActiveWindow.View.Slide
Set oshp = osld.Shapes.addshape(msoShapeOval, 100, 100, 50, 50)
With oshp
.Line.Weight = 3
.Fill.Visible = msoFalse
.Line.ForeColor.RGB = RGB(255, 0, 0)
End With
End Sub
Or write it to open a library presentation stored eg in APPDATA, copy the relevant shape and paste into the active slide the close the library presentation
Paul_Hossler
01-12-2009, 02:56 PM
I had thought about those also (sort of).
The first is just too inflexible to be easily updated, since I have to edit code every change or addition.
The second seems like it would be workable. I could put the "library" presentation some where where it would always open, and copy/paste between the Library and the working one.
I'll have to try that out and see how it works.
Paul
Cosmo
01-12-2009, 03:09 PM
Here's how I would probably tackle this.
Create a master 'library' document with all of the shapes/styles you want to use. I would give each shape a name to describe it. Save it in a specific place on your computer.
Create an add-in which, when loading, locates the master document, and gets the name you set for every shape in the document. Create a menu/button/etc. in the add-in which opens a userform with a popup list of the shape names. On your userform, you can include buttons to create a new shape based on the selected name, or apply the shape's specs to the current selected shape(s).
Now, all you have to do is manage the Library document to add new shapes when needed.
Paul_Hossler
01-13-2009, 05:58 AM
I could probably get that to work.
Still a little hard to maintain, but getting there
Thanks
Paul
TrippyTom
01-13-2009, 04:03 PM
I'm interested in how it turns out for you. I wanted something similar but gave up on it. I ended up finding ShapeStyles made by the wonderful people at PPTOOLS and it worked for my needs.
Here's the link:
http://www.pptools.com/shapestyles/index.html
disclaimer: I am in no way compensated for the "plug" I mentioned above. :)
Paul_Hossler
01-13-2009, 04:24 PM
Thanks for the link.
I'm not good enough with PP VBA to do anything tricky (let alone impressive :rotlaugh: ) to turn out anything close to the PPTools stuff.
I did like the Flash demo
I'll really have to think about some easy way to do it.
I think it'd be handy enough for me to at least make a stab at it, even if it just putting a "palette' of shapes on another slide.
Paul
John Wilson
01-14-2009, 04:14 AM
Hi Paul
You need two basic code blocks
1. to create menus
The basic code is
Sub Auto_Open()
Dim myMainMenuBar As CommandBar
Dim myCustomMenu As CommandBarControl
Dim myTempMenu As CommandBarControl
On Error Resume Next ' ignore error if bar not there to delete
Application.CommandBars.ActiveMenuBar.Controls("addinname").Delete
On Error GoTo errorhandler
Set myMainMenuBar = Application.CommandBars.ActiveMenuBar
Set myCustomMenu = myMainMenuBar.Controls.Add(Type:=msoControlPopup, _
before:=4)'third item
myCustomMenu.Caption = "addinname"
'copy paste this block to get more menu items
'**************************************************************
Set myTempMenu = myCustomMenu.Controls.Add(Type:=msoControlButton)
With myTempMenu
.Caption = "menuname1" 'use menu name eg "add star"
.OnAction = "macro1" ' use name of macro to run
End With
'***************************************************************
Exit Sub
errorhandler:
MsgBox "Sorry there's an error - " & Err.Description, vbCritical
End Sub
And 2 to open the master and copy paste
Try something like this:
Sub macro1()
Dim otarget As Presentation
Dim osource As Presentation
Set otarget = ActivePresentation
'obviously use your own path!
Set osource = Presentations.Open("C:\Documents and Settings\John\Desktop\test.ppt", msoFalse, msoFalse, msoFalse)
osource.Slides(1).Shapes("mystar").Copy ' assumes this is the shapename and it's on slide 1
osource.Close
With otarget.Windows(1).View.Slide.Shapes
.Paste
End With
End Sub
save as a .ppa
Hope that gets you going!
Paul_Hossler
01-14-2009, 08:13 AM
John -- that's sort of the flow I was thinking about.
Q: how to I refer to a slide in an addin? Excel has a ThisWorkbook and an ActiveWorkbook, but PP only has ActivePresentation.
If I store the shape library in an addin, I'd want to copy by object name from the addin, and paste it into the displayed presentation.
Paul
Cosmo
01-14-2009, 08:16 AM
I could be wrong, but from what I remember, add-ins do not include slides. So you'd need a different place to store the shapes/specs, hence my suggestion of a Master library file.
John Wilson
01-14-2009, 08:29 AM
As Cosmo says you can't include slides in an add In.
What the code does is open a master ppt stored in some safe location on the hard drive, copy the relevant shape and closes the master again. It then pastes the shape into the active presentation.
A good location might be Environ("SYSTEMDRIVE") & "\Library\Master.ppt"
(This works even if the drive isn't C:) and equates usually to C:\Library\Master.ppt
Paul_Hossler
01-14-2009, 11:58 AM
Live and learn -- thanks
That will save a lot of head scratching
Paul
lucas
01-14-2009, 12:09 PM
John, your menu example at post #8, does that menu get removed if you uninstall the addin in powerpoint?
John Wilson
01-14-2009, 12:19 PM
Not as it stands but it could be easily deleted with menu > customise
To do it by code delete it every time PPT closes
sub Auto_Close
Application.CommandBars.ActiveMenuBar.Controls("addinname").Delete
End sub
lucas
01-14-2009, 12:56 PM
I thought so. Thanks. I'm venturing into PP and it has some of excels characteristics it seems.
Paul_Hossler
01-16-2009, 10:01 AM
Now if it only had a good macro recorder ......
Paul
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.