PC Review


Reply
Thread Tools Rate Thread

create command buttons using vba

 
 
=?Utf-8?B?SmVmZg==?=
Guest
Posts: n/a
 
      20th Nov 2006
Please help. :-)

I need to create 'Command Buttons' to reside on a worksheet
using VBA. The number of command buttons created will vary.
The command button type is from the 'Control Tool box'

thank you

--
Jeff
 
Reply With Quote
 
 
 
 
Doug Glancy
Guest
Posts: n/a
 
      20th Nov 2006
Jeff,

Here's what I come up with by running the Macro Recorder and a little
tweaking:

Sub make_buttons()
Dim cbutton As OLEObject

Set cbutton = ActiveSheet.OLEObjects.Add(ClassType:="Forms.CommandButton.1",
Link:=False _
, DisplayAsIcon:=False, Left:=173.25, Top:=75.75, Width:=49.5,
Height:=33.75)
Set cbutton = ActiveSheet.OLEObjects.Add(ClassType:="Forms.CommandButton.1",
Link:=False _
, DisplayAsIcon:=False, Left:=258, Top:=78.75, Width:=50.25,
Height:=27.75)

End Sub

hth,

Doug

"Jeff" <(E-Mail Removed)> wrote in message
news:10842F1D-4319-490D-A730-(E-Mail Removed)...
> Please help. :-)
>
> I need to create 'Command Buttons' to reside on a worksheet
> using VBA. The number of command buttons created will vary.
> The command button type is from the 'Control Tool box'
>
> thank you
>
> --
> Jeff



 
Reply With Quote
 
=?Utf-8?B?SmVmZg==?=
Guest
Posts: n/a
 
      21st Nov 2006
Thank you Doug :-)

I need to create command buttons using VBA from the
'Control Box'. To be imbedded on a worksheet.
I won't be using Forms
--
Jeff


"Doug Glancy" wrote:

> Jeff,
>
> Here's what I come up with by running the Macro Recorder and a little
> tweaking:
>
> Sub make_buttons()
> Dim cbutton As OLEObject
>
> Set cbutton = ActiveSheet.OLEObjects.Add(ClassType:="Forms.CommandButton.1",
> Link:=False _
> , DisplayAsIcon:=False, Left:=173.25, Top:=75.75, Width:=49.5,
> Height:=33.75)
> Set cbutton = ActiveSheet.OLEObjects.Add(ClassType:="Forms.CommandButton.1",
> Link:=False _
> , DisplayAsIcon:=False, Left:=258, Top:=78.75, Width:=50.25,
> Height:=27.75)
>
> End Sub
>
> hth,
>
> Doug
>
> "Jeff" <(E-Mail Removed)> wrote in message
> news:10842F1D-4319-490D-A730-(E-Mail Removed)...
> > Please help. :-)
> >
> > I need to create 'Command Buttons' to reside on a worksheet
> > using VBA. The number of command buttons created will vary.
> > The command button type is from the 'Control Tool box'
> >
> > thank you
> >
> > --
> > Jeff

>
>
>

 
Reply With Quote
 
Doug Glancy
Guest
Posts: n/a
 
      21st Nov 2006
Jeff,

When I run this macro it puts 2 buttons from the Control Toolbox on the
active worksheet. It sounds like that's what you want. Does it not do that
for you?

hth,

Doug


"Jeff" <(E-Mail Removed)> wrote in message
news:3AE78420-7098-45E6-A412-(E-Mail Removed)...
> Thank you Doug :-)
>
> I need to create command buttons using VBA from the
> 'Control Box'. To be imbedded on a worksheet.
> I won't be using Forms
> --
> Jeff
>
>
> "Doug Glancy" wrote:
>
>> Jeff,
>>
>> Here's what I come up with by running the Macro Recorder and a little
>> tweaking:
>>
>> Sub make_buttons()
>> Dim cbutton As OLEObject
>>
>> Set cbutton =
>> ActiveSheet.OLEObjects.Add(ClassType:="Forms.CommandButton.1",
>> Link:=False _
>> , DisplayAsIcon:=False, Left:=173.25, Top:=75.75, Width:=49.5,
>> Height:=33.75)
>> Set cbutton =
>> ActiveSheet.OLEObjects.Add(ClassType:="Forms.CommandButton.1",
>> Link:=False _
>> , DisplayAsIcon:=False, Left:=258, Top:=78.75, Width:=50.25,
>> Height:=27.75)
>>
>> End Sub
>>
>> hth,
>>
>> Doug
>>
>> "Jeff" <(E-Mail Removed)> wrote in message
>> news:10842F1D-4319-490D-A730-(E-Mail Removed)...
>> > Please help. :-)
>> >
>> > I need to create 'Command Buttons' to reside on a worksheet
>> > using VBA. The number of command buttons created will vary.
>> > The command button type is from the 'Control Tool box'
>> >
>> > thank you
>> >
>> > --
>> > Jeff

>>
>>
>>



 
Reply With Quote
 
=?Utf-8?B?SmVmZg==?=
Guest
Posts: n/a
 
      21st Nov 2006
Works great Doug.

Can a Loop be used to create numbers of command buttons.
I seach a column for various strings in a Row and create the
number buttons based on the count of strings

For example A1 = Procedure
A22 = Procudure

the count for creating the buttons would be two for the worksheet
for 'Procecure' in column A.

Thank you for your kindness in helping.

Jeff :-)
--
Jeff


"Doug Glancy" wrote:

> Jeff,
>
> When I run this macro it puts 2 buttons from the Control Toolbox on the
> active worksheet. It sounds like that's what you want. Does it not do that
> for you?
>
> hth,
>
> Doug
>
>
> "Jeff" <(E-Mail Removed)> wrote in message
> news:3AE78420-7098-45E6-A412-(E-Mail Removed)...
> > Thank you Doug :-)
> >
> > I need to create command buttons using VBA from the
> > 'Control Box'. To be imbedded on a worksheet.
> > I won't be using Forms
> > --
> > Jeff
> >
> >
> > "Doug Glancy" wrote:
> >
> >> Jeff,
> >>
> >> Here's what I come up with by running the Macro Recorder and a little
> >> tweaking:
> >>
> >> Sub make_buttons()
> >> Dim cbutton As OLEObject
> >>
> >> Set cbutton =
> >> ActiveSheet.OLEObjects.Add(ClassType:="Forms.CommandButton.1",
> >> Link:=False _
> >> , DisplayAsIcon:=False, Left:=173.25, Top:=75.75, Width:=49.5,
> >> Height:=33.75)
> >> Set cbutton =
> >> ActiveSheet.OLEObjects.Add(ClassType:="Forms.CommandButton.1",
> >> Link:=False _
> >> , DisplayAsIcon:=False, Left:=258, Top:=78.75, Width:=50.25,
> >> Height:=27.75)
> >>
> >> End Sub
> >>
> >> hth,
> >>
> >> Doug
> >>
> >> "Jeff" <(E-Mail Removed)> wrote in message
> >> news:10842F1D-4319-490D-A730-(E-Mail Removed)...
> >> > Please help. :-)
> >> >
> >> > I need to create 'Command Buttons' to reside on a worksheet
> >> > using VBA. The number of command buttons created will vary.
> >> > The command button type is from the 'Control Tool box'
> >> >
> >> > thank you
> >> >
> >> > --
> >> > Jeff
> >>
> >>
> >>

>
>
>

 
Reply With Quote
 
Doug Glancy
Guest
Posts: n/a
 
      21st Nov 2006
Jeff,

You're welcome.

This counts the number of "Procedures" in column A and puts buttons at the
top of column B, one for each cell starting in B2:

Sub make_buttons()
Dim i As Long
Dim cbutton As OLEObject

For i = 1 To WorksheetFunction.CountIf(Range("A:A"), "Procedure")
With ActiveSheet.Cells(i, 2)
Set cbutton =
ActiveSheet.OLEObjects.Add(ClassType:="forms.CommandButton.1", _
Left:=.Left, Top:=.Top, Width:=.Width, Height:=.Height)
End With
Next i

End Sub

Let me know if there's more needed.

hth,

Doug


"Jeff" <(E-Mail Removed)> wrote in message
news:4327E625-8B58-4AAB-9864-(E-Mail Removed)...
> Works great Doug.
>
> Can a Loop be used to create numbers of command buttons.
> I seach a column for various strings in a Row and create the
> number buttons based on the count of strings
>
> For example A1 = Procedure
> A22 = Procudure
>
> the count for creating the buttons would be two for the worksheet
> for 'Procecure' in column A.
>
> Thank you for your kindness in helping.
>
> Jeff :-)
> --
> Jeff
>
>
> "Doug Glancy" wrote:
>
>> Jeff,
>>
>> When I run this macro it puts 2 buttons from the Control Toolbox on the
>> active worksheet. It sounds like that's what you want. Does it not do
>> that
>> for you?
>>
>> hth,
>>
>> Doug
>>
>>
>> "Jeff" <(E-Mail Removed)> wrote in message
>> news:3AE78420-7098-45E6-A412-(E-Mail Removed)...
>> > Thank you Doug :-)
>> >
>> > I need to create command buttons using VBA from the
>> > 'Control Box'. To be imbedded on a worksheet.
>> > I won't be using Forms
>> > --
>> > Jeff
>> >
>> >
>> > "Doug Glancy" wrote:
>> >
>> >> Jeff,
>> >>
>> >> Here's what I come up with by running the Macro Recorder and a little
>> >> tweaking:
>> >>
>> >> Sub make_buttons()
>> >> Dim cbutton As OLEObject
>> >>
>> >> Set cbutton =
>> >> ActiveSheet.OLEObjects.Add(ClassType:="Forms.CommandButton.1",
>> >> Link:=False _
>> >> , DisplayAsIcon:=False, Left:=173.25, Top:=75.75, Width:=49.5,
>> >> Height:=33.75)
>> >> Set cbutton =
>> >> ActiveSheet.OLEObjects.Add(ClassType:="Forms.CommandButton.1",
>> >> Link:=False _
>> >> , DisplayAsIcon:=False, Left:=258, Top:=78.75, Width:=50.25,
>> >> Height:=27.75)
>> >>
>> >> End Sub
>> >>
>> >> hth,
>> >>
>> >> Doug
>> >>
>> >> "Jeff" <(E-Mail Removed)> wrote in message
>> >> news:10842F1D-4319-490D-A730-(E-Mail Removed)...
>> >> > Please help. :-)
>> >> >
>> >> > I need to create 'Command Buttons' to reside on a worksheet
>> >> > using VBA. The number of command buttons created will vary.
>> >> > The command button type is from the 'Control Tool box'
>> >> >
>> >> > thank you
>> >> >
>> >> > --
>> >> > Jeff
>> >>
>> >>
>> >>

>>
>>
>>



 
Reply With Quote
 
=?Utf-8?B?SmVmZg==?=
Guest
Posts: n/a
 
      21st Nov 2006
Yes this works great :-)
thank you

All I have to do now is change the command button names each time through
the loop

I believe it should be... forms.CommandButton.i

Hmmmm...
Maybe it will work using the for loop var i


For i = 1 To WorksheetFunction.CountIf(Range("A:A"), "Procedure")
With ActiveSheet.Cells(i, 2)
Set cbutton =
ActiveSheet.OLEObjects.Add(ClassType:="forms.CommandButton.i", _
Left:=.Left, Top:=.Top, Width:=.Width, Height:=.Height)
End With
Next i




--
Jeff


"Doug Glancy" wrote:

> Jeff,
>
> You're welcome.
>
> This counts the number of "Procedures" in column A and puts buttons at the
> top of column B, one for each cell starting in B2:
>
> Sub make_buttons()
> Dim i As Long
> Dim cbutton As OLEObject
>
> For i = 1 To WorksheetFunction.CountIf(Range("A:A"), "Procedure")
> With ActiveSheet.Cells(i, 2)
> Set cbutton =
> ActiveSheet.OLEObjects.Add(ClassType:="forms.CommandButton.1", _
> Left:=.Left, Top:=.Top, Width:=.Width, Height:=.Height)
> End With
> Next i
>
> End Sub
>
> Let me know if there's more needed.
>
> hth,
>
> Doug
>
>
> "Jeff" <(E-Mail Removed)> wrote in message
> news:4327E625-8B58-4AAB-9864-(E-Mail Removed)...
> > Works great Doug.
> >
> > Can a Loop be used to create numbers of command buttons.
> > I seach a column for various strings in a Row and create the
> > number buttons based on the count of strings
> >
> > For example A1 = Procedure
> > A22 = Procudure
> >
> > the count for creating the buttons would be two for the worksheet
> > for 'Procecure' in column A.
> >
> > Thank you for your kindness in helping.
> >
> > Jeff :-)
> > --
> > Jeff
> >
> >
> > "Doug Glancy" wrote:
> >
> >> Jeff,
> >>
> >> When I run this macro it puts 2 buttons from the Control Toolbox on the
> >> active worksheet. It sounds like that's what you want. Does it not do
> >> that
> >> for you?
> >>
> >> hth,
> >>
> >> Doug
> >>
> >>
> >> "Jeff" <(E-Mail Removed)> wrote in message
> >> news:3AE78420-7098-45E6-A412-(E-Mail Removed)...
> >> > Thank you Doug :-)
> >> >
> >> > I need to create command buttons using VBA from the
> >> > 'Control Box'. To be imbedded on a worksheet.
> >> > I won't be using Forms
> >> > --
> >> > Jeff
> >> >
> >> >
> >> > "Doug Glancy" wrote:
> >> >
> >> >> Jeff,
> >> >>
> >> >> Here's what I come up with by running the Macro Recorder and a little
> >> >> tweaking:
> >> >>
> >> >> Sub make_buttons()
> >> >> Dim cbutton As OLEObject
> >> >>
> >> >> Set cbutton =
> >> >> ActiveSheet.OLEObjects.Add(ClassType:="Forms.CommandButton.1",
> >> >> Link:=False _
> >> >> , DisplayAsIcon:=False, Left:=173.25, Top:=75.75, Width:=49.5,
> >> >> Height:=33.75)
> >> >> Set cbutton =
> >> >> ActiveSheet.OLEObjects.Add(ClassType:="Forms.CommandButton.1",
> >> >> Link:=False _
> >> >> , DisplayAsIcon:=False, Left:=258, Top:=78.75, Width:=50.25,
> >> >> Height:=27.75)
> >> >>
> >> >> End Sub
> >> >>
> >> >> hth,
> >> >>
> >> >> Doug
> >> >>
> >> >> "Jeff" <(E-Mail Removed)> wrote in message
> >> >> news:10842F1D-4319-490D-A730-(E-Mail Removed)...
> >> >> > Please help. :-)
> >> >> >
> >> >> > I need to create 'Command Buttons' to reside on a worksheet
> >> >> > using VBA. The number of command buttons created will vary.
> >> >> > The command button type is from the 'Control Tool box'
> >> >> >
> >> >> > thank you
> >> >> >
> >> >> > --
> >> >> > Jeff
> >> >>
> >> >>
> >> >>
> >>
> >>
> >>

>
>
>

 
Reply With Quote
 
=?Utf-8?B?SmVmZg==?=
Guest
Posts: n/a
 
      21st Nov 2006
Sorry about that I asked a dumb question.
It works ok as is.
I was trying to name each command button
like 'Cmd_Select1', 'Cmd_Select2', etc...
as a custom name rather than 'commandbutton1'

thx
Jeff :-)
PS
You help is appreciated
I may actually have time to run out and buy a Turkey
before the rush. :-)
--
Jeff


"Doug Glancy" wrote:

> Jeff,
>
> You're welcome.
>
> This counts the number of "Procedures" in column A and puts buttons at the
> top of column B, one for each cell starting in B2:
>
> Sub make_buttons()
> Dim i As Long
> Dim cbutton As OLEObject
>
> For i = 1 To WorksheetFunction.CountIf(Range("A:A"), "Procedure")
> With ActiveSheet.Cells(i, 2)
> Set cbutton =
> ActiveSheet.OLEObjects.Add(ClassType:="forms.CommandButton.1", _
> Left:=.Left, Top:=.Top, Width:=.Width, Height:=.Height)
> End With
> Next i
>
> End Sub
>
> Let me know if there's more needed.
>
> hth,
>
> Doug
>
>
> "Jeff" <(E-Mail Removed)> wrote in message
> news:4327E625-8B58-4AAB-9864-(E-Mail Removed)...
> > Works great Doug.
> >
> > Can a Loop be used to create numbers of command buttons.
> > I seach a column for various strings in a Row and create the
> > number buttons based on the count of strings
> >
> > For example A1 = Procedure
> > A22 = Procudure
> >
> > the count for creating the buttons would be two for the worksheet
> > for 'Procecure' in column A.
> >
> > Thank you for your kindness in helping.
> >
> > Jeff :-)
> > --
> > Jeff
> >
> >
> > "Doug Glancy" wrote:
> >
> >> Jeff,
> >>
> >> When I run this macro it puts 2 buttons from the Control Toolbox on the
> >> active worksheet. It sounds like that's what you want. Does it not do
> >> that
> >> for you?
> >>
> >> hth,
> >>
> >> Doug
> >>
> >>
> >> "Jeff" <(E-Mail Removed)> wrote in message
> >> news:3AE78420-7098-45E6-A412-(E-Mail Removed)...
> >> > Thank you Doug :-)
> >> >
> >> > I need to create command buttons using VBA from the
> >> > 'Control Box'. To be imbedded on a worksheet.
> >> > I won't be using Forms
> >> > --
> >> > Jeff
> >> >
> >> >
> >> > "Doug Glancy" wrote:
> >> >
> >> >> Jeff,
> >> >>
> >> >> Here's what I come up with by running the Macro Recorder and a little
> >> >> tweaking:
> >> >>
> >> >> Sub make_buttons()
> >> >> Dim cbutton As OLEObject
> >> >>
> >> >> Set cbutton =
> >> >> ActiveSheet.OLEObjects.Add(ClassType:="Forms.CommandButton.1",
> >> >> Link:=False _
> >> >> , DisplayAsIcon:=False, Left:=173.25, Top:=75.75, Width:=49.5,
> >> >> Height:=33.75)
> >> >> Set cbutton =
> >> >> ActiveSheet.OLEObjects.Add(ClassType:="Forms.CommandButton.1",
> >> >> Link:=False _
> >> >> , DisplayAsIcon:=False, Left:=258, Top:=78.75, Width:=50.25,
> >> >> Height:=27.75)
> >> >>
> >> >> End Sub
> >> >>
> >> >> hth,
> >> >>
> >> >> Doug
> >> >>
> >> >> "Jeff" <(E-Mail Removed)> wrote in message
> >> >> news:10842F1D-4319-490D-A730-(E-Mail Removed)...
> >> >> > Please help. :-)
> >> >> >
> >> >> > I need to create 'Command Buttons' to reside on a worksheet
> >> >> > using VBA. The number of command buttons created will vary.
> >> >> > The command button type is from the 'Control Tool box'
> >> >> >
> >> >> > thank you
> >> >> >
> >> >> > --
> >> >> > Jeff
> >> >>
> >> >>
> >> >>
> >>
> >>
> >>

>
>
>

 
Reply With Quote
 
=?Utf-8?B?SmVmZg==?=
Guest
Posts: n/a
 
      21st Nov 2006
Doug

Nameing is no big deal, sorry about that
However what is critical is...
I need to space down each newly created command button
by 8 rows, in the same column so it will align up with
existing data in each row.

B1 button
B9 button
B17 button
..
..
..
jeff :-)

--
Jeff


"Jeff" wrote:

> Sorry about that I asked a dumb question.
> It works ok as is.
> I was trying to name each command button
> like 'Cmd_Select1', 'Cmd_Select2', etc...
> as a custom name rather than 'commandbutton1'
>
> thx
> Jeff :-)
> PS
> You help is appreciated
> I may actually have time to run out and buy a Turkey
> before the rush. :-)
> --
> Jeff
>
>
> "Doug Glancy" wrote:
>
> > Jeff,
> >
> > You're welcome.
> >
> > This counts the number of "Procedures" in column A and puts buttons at the
> > top of column B, one for each cell starting in B2:
> >
> > Sub make_buttons()
> > Dim i As Long
> > Dim cbutton As OLEObject
> >
> > For i = 1 To WorksheetFunction.CountIf(Range("A:A"), "Procedure")
> > With ActiveSheet.Cells(i, 2)
> > Set cbutton =
> > ActiveSheet.OLEObjects.Add(ClassType:="forms.CommandButton.1", _
> > Left:=.Left, Top:=.Top, Width:=.Width, Height:=.Height)
> > End With
> > Next i
> >
> > End Sub
> >
> > Let me know if there's more needed.
> >
> > hth,
> >
> > Doug
> >
> >
> > "Jeff" <(E-Mail Removed)> wrote in message
> > news:4327E625-8B58-4AAB-9864-(E-Mail Removed)...
> > > Works great Doug.
> > >
> > > Can a Loop be used to create numbers of command buttons.
> > > I seach a column for various strings in a Row and create the
> > > number buttons based on the count of strings
> > >
> > > For example A1 = Procedure
> > > A22 = Procudure
> > >
> > > the count for creating the buttons would be two for the worksheet
> > > for 'Procecure' in column A.
> > >
> > > Thank you for your kindness in helping.
> > >
> > > Jeff :-)
> > > --
> > > Jeff
> > >
> > >
> > > "Doug Glancy" wrote:
> > >
> > >> Jeff,
> > >>
> > >> When I run this macro it puts 2 buttons from the Control Toolbox on the
> > >> active worksheet. It sounds like that's what you want. Does it not do
> > >> that
> > >> for you?
> > >>
> > >> hth,
> > >>
> > >> Doug
> > >>
> > >>
> > >> "Jeff" <(E-Mail Removed)> wrote in message
> > >> news:3AE78420-7098-45E6-A412-(E-Mail Removed)...
> > >> > Thank you Doug :-)
> > >> >
> > >> > I need to create command buttons using VBA from the
> > >> > 'Control Box'. To be imbedded on a worksheet.
> > >> > I won't be using Forms
> > >> > --
> > >> > Jeff
> > >> >
> > >> >
> > >> > "Doug Glancy" wrote:
> > >> >
> > >> >> Jeff,
> > >> >>
> > >> >> Here's what I come up with by running the Macro Recorder and a little
> > >> >> tweaking:
> > >> >>
> > >> >> Sub make_buttons()
> > >> >> Dim cbutton As OLEObject
> > >> >>
> > >> >> Set cbutton =
> > >> >> ActiveSheet.OLEObjects.Add(ClassType:="Forms.CommandButton.1",
> > >> >> Link:=False _
> > >> >> , DisplayAsIcon:=False, Left:=173.25, Top:=75.75, Width:=49.5,
> > >> >> Height:=33.75)
> > >> >> Set cbutton =
> > >> >> ActiveSheet.OLEObjects.Add(ClassType:="Forms.CommandButton.1",
> > >> >> Link:=False _
> > >> >> , DisplayAsIcon:=False, Left:=258, Top:=78.75, Width:=50.25,
> > >> >> Height:=27.75)
> > >> >>
> > >> >> End Sub
> > >> >>
> > >> >> hth,
> > >> >>
> > >> >> Doug
> > >> >>
> > >> >> "Jeff" <(E-Mail Removed)> wrote in message
> > >> >> news:10842F1D-4319-490D-A730-(E-Mail Removed)...
> > >> >> > Please help. :-)
> > >> >> >
> > >> >> > I need to create 'Command Buttons' to reside on a worksheet
> > >> >> > using VBA. The number of command buttons created will vary.
> > >> >> > The command button type is from the 'Control Tool box'
> > >> >> >
> > >> >> > thank you
> > >> >> >
> > >> >> > --
> > >> >> > Jeff
> > >> >>
> > >> >>
> > >> >>
> > >>
> > >>
> > >>

> >
> >
> >

 
Reply With Quote
 
Doug Glancy
Guest
Posts: n/a
 
      21st Nov 2006
Jeff,

This names them as you wanted and spaces the buttons every 8 rows:

Sub make_buttons()
Dim i As Long
Dim cbutton As OLEObject

For i = 1 To WorksheetFunction.CountIf(Range("A:A"), "Procedure")
With ActiveSheet.Cells(i + ((i - 1) * 7), 2)
Set cbutton =
ActiveSheet.OLEObjects.Add(ClassType:="forms.CommandButton.1", _
Left:=.Left, Top:=.Top, Width:=.Width, Height:=.Height)
cbutton.Name = "Cmd_Select" & i
End With
Next i

End Sub

Happy Thanksgiving,

Doug


"Jeff" <(E-Mail Removed)> wrote in message
news:73AA87BB-7F61-4F5D-BF94-(E-Mail Removed)...
> Doug
>
> Nameing is no big deal, sorry about that
> However what is critical is...
> I need to space down each newly created command button
> by 8 rows, in the same column so it will align up with
> existing data in each row.
>
> B1 button
> B9 button
> B17 button
> .
> .
> .
> jeff :-)
>
> --
> Jeff
>
>
> "Jeff" wrote:
>
>> Sorry about that I asked a dumb question.
>> It works ok as is.
>> I was trying to name each command button
>> like 'Cmd_Select1', 'Cmd_Select2', etc...
>> as a custom name rather than 'commandbutton1'
>>
>> thx
>> Jeff :-)
>> PS
>> You help is appreciated
>> I may actually have time to run out and buy a Turkey
>> before the rush. :-)
>> --
>> Jeff
>>
>>
>> "Doug Glancy" wrote:
>>
>> > Jeff,
>> >
>> > You're welcome.
>> >
>> > This counts the number of "Procedures" in column A and puts buttons at
>> > the
>> > top of column B, one for each cell starting in B2:
>> >
>> > Sub make_buttons()
>> > Dim i As Long
>> > Dim cbutton As OLEObject
>> >
>> > For i = 1 To WorksheetFunction.CountIf(Range("A:A"), "Procedure")
>> > With ActiveSheet.Cells(i, 2)
>> > Set cbutton =
>> > ActiveSheet.OLEObjects.Add(ClassType:="forms.CommandButton.1", _
>> > Left:=.Left, Top:=.Top, Width:=.Width, Height:=.Height)
>> > End With
>> > Next i
>> >
>> > End Sub
>> >
>> > Let me know if there's more needed.
>> >
>> > hth,
>> >
>> > Doug
>> >
>> >
>> > "Jeff" <(E-Mail Removed)> wrote in message
>> > news:4327E625-8B58-4AAB-9864-(E-Mail Removed)...
>> > > Works great Doug.
>> > >
>> > > Can a Loop be used to create numbers of command buttons.
>> > > I seach a column for various strings in a Row and create the
>> > > number buttons based on the count of strings
>> > >
>> > > For example A1 = Procedure
>> > > A22 = Procudure
>> > >
>> > > the count for creating the buttons would be two for the worksheet
>> > > for 'Procecure' in column A.
>> > >
>> > > Thank you for your kindness in helping.
>> > >
>> > > Jeff :-)
>> > > --
>> > > Jeff
>> > >
>> > >
>> > > "Doug Glancy" wrote:
>> > >
>> > >> Jeff,
>> > >>
>> > >> When I run this macro it puts 2 buttons from the Control Toolbox on
>> > >> the
>> > >> active worksheet. It sounds like that's what you want. Does it not
>> > >> do
>> > >> that
>> > >> for you?
>> > >>
>> > >> hth,
>> > >>
>> > >> Doug
>> > >>
>> > >>
>> > >> "Jeff" <(E-Mail Removed)> wrote in message
>> > >> news:3AE78420-7098-45E6-A412-(E-Mail Removed)...
>> > >> > Thank you Doug :-)
>> > >> >
>> > >> > I need to create command buttons using VBA from the
>> > >> > 'Control Box'. To be imbedded on a worksheet.
>> > >> > I won't be using Forms
>> > >> > --
>> > >> > Jeff
>> > >> >
>> > >> >
>> > >> > "Doug Glancy" wrote:
>> > >> >
>> > >> >> Jeff,
>> > >> >>
>> > >> >> Here's what I come up with by running the Macro Recorder and a
>> > >> >> little
>> > >> >> tweaking:
>> > >> >>
>> > >> >> Sub make_buttons()
>> > >> >> Dim cbutton As OLEObject
>> > >> >>
>> > >> >> Set cbutton =
>> > >> >> ActiveSheet.OLEObjects.Add(ClassType:="Forms.CommandButton.1",
>> > >> >> Link:=False _
>> > >> >> , DisplayAsIcon:=False, Left:=173.25, Top:=75.75,
>> > >> >> Width:=49.5,
>> > >> >> Height:=33.75)
>> > >> >> Set cbutton =
>> > >> >> ActiveSheet.OLEObjects.Add(ClassType:="Forms.CommandButton.1",
>> > >> >> Link:=False _
>> > >> >> , DisplayAsIcon:=False, Left:=258, Top:=78.75, Width:=50.25,
>> > >> >> Height:=27.75)
>> > >> >>
>> > >> >> End Sub
>> > >> >>
>> > >> >> hth,
>> > >> >>
>> > >> >> Doug
>> > >> >>
>> > >> >> "Jeff" <(E-Mail Removed)> wrote in message
>> > >> >> news:10842F1D-4319-490D-A730-(E-Mail Removed)...
>> > >> >> > Please help. :-)
>> > >> >> >
>> > >> >> > I need to create 'Command Buttons' to reside on a worksheet
>> > >> >> > using VBA. The number of command buttons created will vary.
>> > >> >> > The command button type is from the 'Control Tool box'
>> > >> >> >
>> > >> >> > thank you
>> > >> >> >
>> > >> >> > --
>> > >> >> > Jeff
>> > >> >>
>> > >> >>
>> > >> >>
>> > >>
>> > >>
>> > >>
>> >
>> >
>> >



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Create Command buttons wizard Sasha B Microsoft Access Forms 1 12th Sep 2008 11:52 PM
How to create 'command buttons' to hide/reveal text in Word? =?Utf-8?B?dGxpZ2V0dA==?= Microsoft Word Document Management 6 18th Feb 2006 07:16 PM
Seeking a way to create voting buttons from a command line mail script seemore_babunga Microsoft Outlook 4 8th Apr 2005 02:43 PM
Create a search Field within a worksheet to search command buttons =?Utf-8?B?RWQgUA==?= Microsoft Excel Programming 1 14th Dec 2004 08:04 PM
Using combo boxes and command buttons to create a query jon Microsoft Access 0 15th Sep 2003 08:05 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:37 AM.