Thread: [Solved] Command Button
View Single Post
 
Old 02-26-2011, 12:50 PM
macropod's Avatar
macropod macropod is offline Windows 7 32bit Office 2000
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Quote:
Originally Posted by cksm4 View Post
I will have no idea how many activites the user will need. There could be 1 or 100. Since each activity is a quick part, they are basically a copy of the first activity. So each command button will have the same base name.

Stessing that I am still new to VBA, I am guessing that you are saying to create code that runs on all command buttons. And from this run actions based on the name of the command button selected. So if the name of this button that is repeated in each activity is MyCommandButton, then the code would refer to the button as Like MyCommandButton*. Right/wrong?
Hi Brock,

As you create each new command button via Quick Parts, the button number for the new button should increment. They'll get the default command button names - starting at CommandButton11! So you'll end up with CommandButton1, CommandButton11, CommandButton12, CommandButton13 and so on. And they'll all have the same caption that you gave the Quick Parts command button. So you'll need subs corresponding to each of these:
Code:
Private Sub CommandButton1_Click()
Call MySub
End Sub
 
Private Sub CommandButton11_Click()
Call MySub
End Sub 
 
Private Sub CommandButton12_Click()
Call MySub
End Sub
etc, and, in the same module:
Code:
Private Sub MySub()
'the generic code that does the real work.
End Sub
Replicating the command button code for as many as you're likely to need is pretty much a copy/paste operation, with edits to the command button numbers.

While all of the above is feasible - and fairly easily done - I'm starting to wonder if you wouldn't be better off having a small userform with just a single command button floating over the document, rather than optentially having a plethora of ActiveX buttons in the document as a result of being replicated by Quick Parts. That way, there'd be no concerns over how many elements of your document might be created via Quick Parts. The generic macro could be coded to work with whatever range in the document the user has selected (or some other range, if you prefer).
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote