PDA

View Full Version : Calling a macro from another macro



andy_uk
08-09-2004, 05:14 PM
Not a question, just sharing an experience. It'll highlight the extent to which I'm struggling with the whole "object" concept, at the same time if someone searches for the same thing it might help, so what the hey(?)

So I had a UserForm with a text box and a command button on. But I wanted to store the actual button code in a separate module, for the sake of organisation (my UserForm mod is 3 feet long already!).

So I had something like

Private Sub CommandButton1_Click()
Macro1
End Sub

Macro1 said something like

Range("Sheet1!A1") = TextBox1

It took me about 10 minutes to figure that I had to say

Range("Sheet1!A1") = UserForm1.TextBox1

I guess the irony is that I covered the object concept for the worksheet (Sheet1!A1), then completely overlooked it for the form. :blush

HTH someone, sometime.

Rgds,
Andy

jamescol
08-09-2004, 08:06 PM
Andy,
Thing is - you'll never make that same mistake again! :) I always learn better when I struggle to figure out something like that.

James

Smitty
08-09-2004, 09:48 PM
The struggle is what makes us all learn!

I'll bet we're all gonna benefit from the VBA Certification project! (Thanks Anne!)

Smitty

Zack Barresse
08-09-2004, 10:46 PM
The struggle is what makes us all learn!


In the great words of Joe Was .... Try and try again, the way of the Coder!!

CBrine
08-10-2004, 07:31 AM
Andy,
Reminds me of the time I had to reference a checkbox on a Userform, it took me about 1/2 hour to figure out how to do it. So don't feel bad about 10 minutes. The worst, is once you figure it out, your kicking yourself cause it's so obvious.

Tommy
08-10-2004, 07:54 AM
Location, Location, Location. Now where was I?

OOP is another way to say oops.