Sending the Command Button Obj to another procedure

kbdavis11

New Member
Joined
Dec 8, 2014
Messages
30
I am creating a blank worksheet with various procedures that automates another application (AccuTerm Terminal).

My issue is that I am wanting to add a line to each ActiveX Command Button that will resize the button to a range.

For example, let's say I have this command button:

Code:
Private Sub CommandButton2_Click()
    setButtonSize Me.Range("B2")
    GrabTriggerReports
End Sub

The `setButtonSize` is the procedure that is suppose to be setting the size of the button to the size of the cell: `Me.Range("B2")`.

The method in `setButtonSize` is:

Code:
Sub setButtonSize(rng As Range)
    With Application.Caller
        .Left = rng.Left
        .Top = rng.Top
        .Width = rng.Width
        .Height = rng.Height
    End With
End Sub

But `.Caller` doesn't appear to want to work, as I am getting an Object Required error. Of course, I could add these lines of code to each button:

Code:
With CommandButton2
    .Left = rng.Left
    .Top = rng.Top
    .Width = rng.Width
    .Height = rng.Height
End With

It is my preference not to do this.

So, how would I be able to send the `CommandButtonX` obj to the `setButtonSize` routine?

Thanks!
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Hi,
Try this update to your code

Code:
Sub SetButtonSize(ByVal rng As Range, ByVal CmdButton As Object)
    With CmdButton
        .Left = rng.Left
        .Top = rng.Top
        .Width = rng.Width
        .Height = rng.Height
    End With
End Sub


to call

Code:
Private Sub CommandButton2_Click()
    SetButtonSize Me.Range("B2"), Me.CommandButton2
End Sub

Dave
 
Upvote 0

Forum statistics

Threads
1,223,956
Messages
6,175,614
Members
452,661
Latest member
Nonhle

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top