Stop macro from running more than once?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Ive added a Combobox to my presentation (set up with a macro) to run when an
action buttion is clicked. If you click the action buttion more than once,
the content repeats itself.

How do you stop the content from repeating in the combobox even if you click
the action buttion more than once? Please see the folowing code...

Thanks!

Sub ComboBox1_Change()

ComboBox1.AddItem ("Proprietary Information")
ComboBox1.AddItem ("Employee Information")
ComboBox1.AddItem ("Customer Information")
ComboBox1.AddItem ("Personal Information")
ComboBox1.AddItem ("Other Information")

End Sub
 
A couple of ways come to mind:

1. You could name the action button the macro is tied to (ButtonClicked) and
have a line of code that hides the button after clicked. That way you can't
click it again. You would obviously need some sort of "initialization" code
that set it back to True so when you get to the slide it is visible. If the
button is on Slide 1, the code to hide it would be (after it is named of
course):

ActivePresentation.Slides(1).Shapes("ButtonClicked").Visible = False

2. You could have a variable "ButtonClicked" that is set to False upon some
sort of initialization. When the button is clicked, it runs an IF...Then
clause. If it is "False" it loads the ComboBox with your stuff, THEN sets
"ButtonClicked" to True. If you click the button again, it will skip the
ComboBox AddItem part of the code and just exit the Sub.
 
Another method:

Private Sub ComboBox1_GotFocus()
If ComboBox1.ListCount < 2 Then
ComboBox1.AddItem ("Proprietary Information")
ComboBox1.AddItem ("Employee Information")
ComboBox1.AddItem ("Customer Information")
ComboBox1.AddItem ("Personal Information")
ComboBox1.AddItem ("Other Information")
End If
End Sub


--

Bill Dilworth
Microsoft PPT MVP Team
Users helping fellow users.
===============
Please spend a few minutes checking vestprog2@
out www.pptfaq.com This link will yahoo.
answer most of your questions, before com
you think to ask them.

Change org to com to defuse anti-spam,
ant-virus, anti-nuisance misdirection.
..
..
 
Duh! Much easier than mine. And to think I almost got that round peg in
that square hole!
 
Change the macro to:

Sub ComboBox1_Change()
ComboBox1.Clear
ComboBox1.AddItem ("Proprietary Information")
ComboBox1.AddItem ("Employee Information")
ComboBox1.AddItem ("Customer Information")
ComboBox1.AddItem ("Personal Information")
ComboBox1.AddItem ("Other Information")
End Sub

- Chirag

PowerShow - View multiple PowerPoint slide shows simultaneously
http://officeone.mvps.org/powershow/powershow.html
 
Thank you...

Does it have to be "Private Sub" as opposed to "Sub"? How are the two
different?


Then
 
Thank you....This worked great!

Chirag said:
Change the macro to:

Sub ComboBox1_Change()
ComboBox1.Clear
ComboBox1.AddItem ("Proprietary Information")
ComboBox1.AddItem ("Employee Information")
ComboBox1.AddItem ("Customer Information")
ComboBox1.AddItem ("Personal Information")
ComboBox1.AddItem ("Other Information")
End Sub

- Chirag

PowerShow - View multiple PowerPoint slide shows simultaneously
http://officeone.mvps.org/powershow/powershow.html
 
The problem with this method, Chirag, is that it clears the selection made
by the act of selecting it. I know this because I beat my head against a
wall trying to figure out why I could not select an item from a list I
updated this way.

However, you can still combine the two methods and use:

Sub ComboBox1_Change()

If ComboBox1.listCount <2 then
ComboBox1.Clear
ComboBox1.AddItem ("Proprietary Information")
ComboBox1.AddItem ("Employee Information")
ComboBox1.AddItem ("Customer Information")
ComboBox1.AddItem ("Personal Information")
ComboBox1.AddItem ("Other Information")
End If

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top