Results 1 to 8 of 8
  1. #1
    Lounger
    Join Date
    Nov 2008
    Location
    England, Yate, Bristol
    Posts
    49
    Thanks
    4
    Thanked 0 Times in 0 Posts
    I have a program in PowerPoint that has a grid of command buttons. These change colour or change visibility according to user actions.

    I want to reset all the command buttons to visible to start a new game, but have to use a line of code for every button.

    Can I run a loop that changes, for example CommandButton1 to CommandButton9.visibility to True.

    All the code is on one slide and the whole game is one slide.

    Thanks. I can live with lines of code, but want it to look neater.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 18 Times in 18 Posts
    Something like this:

    Code:
    Dim i As Integer
    For i = 1 To 9
      Me.Shapes("CommandButton" & i).Visible = True
    Next i
    This assumes that the code is in the code module belonging to the slide. If it's in a general module, you can use

    Code:
    Dim i As Integer
    For i = 1 To 9
      ActivePresentation.Slides(1).Shapes("CommandButton" & i).Visible = True
    Next i

  3. #3
    Lounger
    Join Date
    Nov 2008
    Location
    England, Yate, Bristol
    Posts
    49
    Thanks
    4
    Thanked 0 Times in 0 Posts
    [quote name='HansV' post='787657' date='05-Aug-2009 15:33']Something like this:

    Code:
    Dim i As Integer
    For i = 1 To 9
      Me.Shapes("CommandButton" & i).Visible = True
    Next i
    This assumes that the code is in the code module belonging to the slide. If it's in a general module, you can use

    Code:
    Dim i As Integer
    For i = 1 To 9
      ActivePresentation.Slides(1).Shapes("CommandButton" & i).Visible = True
    Next i
    [/quote]


    Thanks Hans. Perfect

  4. #4
    Lounger
    Join Date
    Nov 2008
    Location
    England, Yate, Bristol
    Posts
    49
    Thanks
    4
    Thanked 0 Times in 0 Posts
    [quote name='peterinth' post='787697' date='05-Aug-2009 21:45']Thanks Hans. Perfect[/quote]

    This actually works for images, but it doesn't work for a commandbutton.

    I have a grid made up of 9 command buttons called Grid1 to Grid9 and 9 images called imgXgrid1 to imgXgrid9

    as I said, the images in the for-next loop works fine, but not the command button.

    Me.Shapes("imgXgrid" & i).Visible = False
    Me.Shapes("Grid" & i).Visible = True

    If take it out of the for-next loop like this:

    Grid1.visible = True

    it's OK

    Any idea why please?

  5. #5
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,534
    Thanks
    3
    Thanked 147 Times in 140 Posts
    Do you get the Grid# series of names appearing in the immediate window when you run this
    Code:
    Dim i As Integer
    For i = 1 To ActivePresentation.Slides(1).Shapes.Count
      ActivePresentation.Slides(1).Shapes(i).Visible = True
      Debug.Print ActivePresentation.Slides(1).Shapes(i).Name
    Next i
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  6. #6
    Lounger
    Join Date
    Nov 2008
    Location
    England, Yate, Bristol
    Posts
    49
    Thanks
    4
    Thanked 0 Times in 0 Posts
    [quote name='Andrew Lockton' post='787879' date='07-Aug-2009 04:58']Do you get the Grid# series of names appearing in the immediate window when you run this
    Code:
    Dim i As Integer
    For i = 1 To ActivePresentation.Slides(1).Shapes.Count
      ActivePresentation.Slides(1).Shapes(i).Visible = True
      Debug.Print ActivePresentation.Slides(1).Shapes(i).Name
    Next i
    [/quote]

    Yes Andrew all the Grid1 to Grid9 show in the immediate window list

  7. #7
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 18 Times in 18 Posts
    You're right. This is bizarre behavior: the buttons do get hidden in design view (which is where I tested), but not in slideshow view (where you want it of course).

    So perhaps you could use shapes such as rectangles, images or action buttons. You can assign macro action to such shapes too, and they will get hidden in slideshow view.

  8. #8
    Lounger
    Join Date
    Nov 2008
    Location
    England, Yate, Bristol
    Posts
    49
    Thanks
    4
    Thanked 0 Times in 0 Posts
    [quote name='HansV' post='787890' date='07-Aug-2009 09:00']You're right. This is bizarre behavior: the buttons do get hidden in design view (which is where I tested), but not in slideshow view (where you want it of course).

    So perhaps you could use shapes such as rectangles, images or action buttons. You can assign macro action to such shapes too, and they will get hidden in slideshow view.[/quote]


    Thanks again.

Posting Permissions

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