Consulting

Results 1 to 16 of 16

Thread: Solved: "Library" of formatted shapes

  1. #1
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,726
    Location

    Solved: "Library" of formatted shapes

    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

    Paul

  2. #2
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,094
    Location
    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

    [vba]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[/vba]

    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
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  3. #3
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,726
    Location
    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

  4. #4
    VBAX Contributor
    Joined
    May 2008
    Posts
    198
    Location
    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.

  5. #5
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,726
    Location
    I could probably get that to work.

    Still a little hard to maintain, but getting there

    Thanks

    Paul

  6. #6
    VBAX Expert TrippyTom's Avatar
    Joined
    Jul 2005
    Location
    New York, NY (USA)
    Posts
    556
    Location
    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.
    Office 2010, Windows 7
    goal: to learn the most efficient way

  7. #7
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,726
    Location
    Thanks for the link.

    I'm not good enough with PP VBA to do anything tricky (let alone impressive ) 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

  8. #8
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,094
    Location
    Hi Paul

    You need two basic code blocks

    1. to create menus

    The basic code is

    [vba]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[/vba]

    And 2 to open the master and copy paste

    Try something like this:

    [vba]
    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[/vba]

    save as a .ppa

    Hope that gets you going!
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  9. #9
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,726
    Location
    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

  10. #10
    VBAX Contributor
    Joined
    May 2008
    Posts
    198
    Location
    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.

  11. #11
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,094
    Location
    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
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  12. #12
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,726
    Location
    Live and learn -- thanks

    That will save a lot of head scratching

    Paul

  13. #13
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    John, your menu example at post #8, does that menu get removed if you uninstall the addin in powerpoint?
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  14. #14
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,094
    Location
    Not as it stands but it could be easily deleted with menu > customise

    To do it by code delete it every time PPT closes

    [vba]sub Auto_Close
    Application.CommandBars.ActiveMenuBar.Controls("addinname").Delete
    End sub
    [/vba]
    Last edited by John Wilson; 01-14-2009 at 12:39 PM.
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  15. #15
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    I thought so. Thanks. I'm venturing into PP and it has some of excels characteristics it seems.
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  16. #16
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,726
    Location
    Now if it only had a good macro recorder ......


    Paul

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •