PDA

View Full Version : VBA PowePoint Images Help



jaybeeb
12-05-2008, 07:13 AM
Complete Beginner here, I have a PowerPoint presentation which I need to code some VB into.
Basically I have a form that opens when the user opens the presentation with two different options. Depending on which option is chosen certain pictures during the presentation will be shown. Where there is pics there is 1 for each option chosen they are the exact same size and on top of each other. I have my form made up with the selection box but not sure how to link it up to the pictures which are to become visible/invisible
Any help would be greatly appreciated.

jaybeeb
12-05-2008, 08:20 AM
Here is what I have so far, but am getting an error "Else without If"??

Does this look correct for what I want to do? Just trying to get something working now thats why I have them both set to false.

Public Sub populate()
mdlContentCombo.AddItem "IIW", 0
mdlContentCombo.AddItem "BDW", 1
End Sub


Private Sub okBtn_Click()
selection = mdlContentCombo.Value

If selection = O Then ActivePresentation.Slides(10).Shapes("Picture 4").Visible = False

Else
ActivePresentation.Slides(10).Shapes("Picture 4").Visible = False
End If

hide
End Sub

John Wilson
12-05-2008, 12:44 PM
Here is what I have so far, but am getting an error "Else without If"??

Does this look correct for what I want to do? Just trying to get something working now thats why I have them both set to false.

Public Sub populate()
mdlContentCombo.AddItem "IIW", 0
mdlContentCombo.AddItem "BDW", 1
End Sub


Private Sub okBtn_Click()
selection = mdlContentCombo.Value

If selection = O Then ActivePresentation.Slides(10).Shapes("Picture 4").Visible = False

Else
ActivePresentation.Slides(10).Shapes("Picture 4").Visible = False
End If

hide
End Sub

You ned to change to this



Public Sub populate()
mdlContentCombo.AddItem "IIW", 0
mdlContentCombo.AddItem "BDW", 1
End Sub



Private Sub okBtn_Click()
selection = mdlContentCombo.Value


If selection = O Then
ActivePresentation.Slides(10).Shapes("Picture 4").Visible = False


Else
ActivePresentation.Slides(10).Shapes("Picture 4").Visible = False
End If


hide
End Sub

jaybeeb
12-07-2008, 10:57 AM
Thanks John, could you tell me what you think is the best way of doing this as it still is not working properly the way I have it. When I run the macro and one of the images dissapears. It stays as visible = false so the image doesnt appear again.

John Wilson
12-07-2008, 11:19 AM
Thanks John, could you tell me what you think is the best way of doing this as it still is not working properly the way I have it. When I run the macro and one of the images dissapears. It stays as visible = false so the image doesnt appear again.

I would move the correct picture in front of the other.

If Selection = O Then
ActivePresentation.Slides(10).Shapes("Picture 4").ZOrder (msoBringToFront)

Else
ActivePresentation.Slides(10).Shapes("Picture 4").ZOrder (msoBringToFront)
End If

jaybeeb
12-07-2008, 11:38 AM
John, thanks for the help - yes that is a much nicer idea. But the problem I am having now is even if the condition is true it will still only run the 'else' statement?

Here is my code now as it stands:



Public Sub populate()
mdlContentCombo.AddItem "HPDM", 0
mdlContentCombo.AddItem "BDW", 1
End Sub


Private Sub okBtn_Click()
selection = mdlContentCombo.Value

If selection = "0" Then
ActivePresentation.Slides(10).Shapes("Picture 5").ZOrder (msoBringToFront)

Else
ActivePresentation.Slides(10).Shapes("Picture 4").ZOrder (msoBringToFront)
End If

hide
End Sub

John Wilson
12-07-2008, 12:55 PM
If strselec = "HPDM" Then


Remove the hide
Don't use selection its a reserved word

jaybeeb
12-07-2008, 02:08 PM
Fair Play John. Thats spot on!