Consulting

Results 1 to 8 of 8

Thread: Solved: toggle an object on/off?

  1. #1
    VBAX Expert TrippyTom's Avatar
    Joined
    Jul 2005
    Location
    New York, NY (USA)
    Posts
    556
    Location

    Solved: toggle an object on/off?

    Hi everyone...

    I'm trying to make a macro that will toggle my predefined set of guidelines in PowerPoint. It's almost working (see partial code below) but I want to figure out a way to toggle the line on/off. And when I say off I mean not setting the .visible property to msoFalse. I don't want to be able to select the line at all when it's toggled off.

    Here's my code:
    [vba]
    ActiveWindow.Selection.SlideRange.Shapes.AddLine(342, 0, 342, 540).Select
    With ActiveWindow.Selection.ShapeRange
    .Name = "x2"
    .Line.Weight = 0.05
    .Line.ForeColor.RGB = RGB(255, 0, 0)
    End With
    [/vba]

    Do you think this is possible?
    Office 2010, Windows 7
    goal: to learn the most efficient way

  2. #2
    VBAX Expert TrippyTom's Avatar
    Joined
    Jul 2005
    Location
    New York, NY (USA)
    Posts
    556
    Location
    I guess my 2nd question would be:
    Can I lock an object from being moved?
    Office 2010, Windows 7
    goal: to learn the most efficient way

  3. #3
    Moderator VBAX Master geekgirlau's Avatar
    Joined
    Aug 2004
    Location
    Melbourne, Australia
    Posts
    1,464
    Location
    Just a thought - what about putting the guideline on the slide master? Doesn't lock it, but certainly makes it much more difficult to get to.

  4. #4
    VBAX Expert TrippyTom's Avatar
    Joined
    Jul 2005
    Location
    New York, NY (USA)
    Posts
    556
    Location
    hmmm... good idea

    Still not sure how to toggle it on/off.
    Office 2010, Windows 7
    goal: to learn the most efficient way

  5. #5
    VBAX Expert TrippyTom's Avatar
    Joined
    Jul 2005
    Location
    New York, NY (USA)
    Posts
    556
    Location
    Well, I did some testing and if it's used as a 2nd slide master, objects won't snap to it, so that won't work.

    I'm back to square one. I want to:
    1) Create the lines (done)
    2) Group them
    3) Somehow toggle them on/off on the current slide with a button (doesn't have to be document wide).
    Office 2010, Windows 7
    goal: to learn the most efficient way

  6. #6
    VBAX Expert TrippyTom's Avatar
    Joined
    Jul 2005
    Location
    New York, NY (USA)
    Posts
    556
    Location
    Would it make a difference if I defined my objects as a class? Would it be easier to work with them that way?
    Office 2010, Windows 7
    goal: to learn the most efficient way

  7. #7
    VBAX Expert TrippyTom's Avatar
    Joined
    Jul 2005
    Location
    New York, NY (USA)
    Posts
    556
    Location
    I changed my macro to put the lines in a Collection, them I marked each line with a specific key ("x1", "x2", etc).

    Now I want to implement a toggle by checking if the lines already exist each time the macro is run. If they do, I want to remove all the lines.
    Is this possible?

    This is my code so far:
    Sub GuidesAdd()
    Dim myCol As New Collection
    Dim i As Long
     
        With myCol
            .Add ActiveWindow.Selection.SlideRange.Shapes.AddLine(23.76, 0, 23.76, 540), "x1"
            .Add ActiveWindow.Selection.SlideRange.Shapes.AddLine(342, 0, 342, 540), "x2"
            .Add ActiveWindow.Selection.SlideRange.Shapes.AddLine(360, 0, 360, 540), "x3"
            .Add ActiveWindow.Selection.SlideRange.Shapes.AddLine(377.28, 0, 377.28, 540), "x4"
            .Add ActiveWindow.Selection.SlideRange.Shapes.AddLine(696.24, 0, 696.24, 540), "x5"
            .Add ActiveWindow.Selection.SlideRange.Shapes.AddLine(0, 48.24, 720, 48.24), "y1"
            .Add ActiveWindow.Selection.SlideRange.Shapes.AddLine(0, 66.24, 720, 66.24), "y2"
            .Add ActiveWindow.Selection.SlideRange.Shapes.AddLine(0, 102.24, 720, 102.24), "y3"
            .Add ActiveWindow.Selection.SlideRange.Shapes.AddLine(0, 120.24, 720, 120.24), "y4"
            .Add ActiveWindow.Selection.SlideRange.Shapes.AddLine(0, 300.24, 720, 300.24), "y5"
            .Add ActiveWindow.Selection.SlideRange.Shapes.AddLine(0, 476.64, 720, 476.64), "y6"
        End With
        For i = myCol.Count To 1 Step -1
            myCol(i).Line.Weight = 0.05
            myCol(i).Line.ForeColor.RGB = RGB(255, 0, 0)
        Next i
    End Sub
    Office 2010, Windows 7
    goal: to learn the most efficient way

  8. #8
    VBAX Expert TrippyTom's Avatar
    Joined
    Jul 2005
    Location
    New York, NY (USA)
    Posts
    556
    Location
    Well, some of you may be happy to know I'm going to mark this solved because I ended up going in a completely different direction with this, and it works.

    Thanks anyway.
    Office 2010, Windows 7
    goal: to learn the most efficient way

Posting Permissions

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