View Single Post
  #8   Report Post  
Posted to microsoft.public.excel.programming
Norman Jones Norman Jones is offline
external usenet poster
 
Posts: 5,302
Default Connecting Modules in VBA

Hi Jenny,

I opened a new workbook.
On sheet2 I added a button from the Control Toolbox. I right-clicked the
command button and pasted:

'==============
Sub CommandButton1_Click()
CommandButton1.Caption = "refresh critical ratio table"
Call ValueSearch
End Sub
'<<==============

From the VBE menus:

Tools | Insert | Module

and I pasted:

'==============
Public Sub ValueSearch()
MsgBox "HELLO"
End Sub
'<<==============

Of course, in your macro, the MsgBox line will be replaced with other
instructions.

I returned to the button sheet and clicked the button: The button's caption
was changed and the Hello message appeared.

Your experience should not differ materially.

---
Regards,
Norman



"Jenny" wrote in message
...
Hi Norman,
Yeah, I copy and pasted the name to make sure it wasn't misspelt, I am
only
dealing with one 3 worksheet workbook, and... this might be it.... the
command button code is in the module for the worksheet that contains the
command button, should it be in the same module as the procedure I am
trying
to call?
Thanks!
Jenny

"Norman Jones" wrote:

Hi Jenny,

(1) Check that the macro name is spelled correctly.
(2) Is the macro in a standard module in the same workbook as the
command button?
(3) Where is the command button code?


---
Regards,
Norman


"Jenny" wrote in message
...
Hi again,
So, I am definitely getting closer, but now the sub function is not
defined,
specifically valuesearch. How can I define it?

Jenny

"Norman Jones" wrote:

Hi Jenny,

Try:
'==============
Sub CommandButton1_Click()
CommandButton1.Caption = "refresh critical ratio table"
Call ValueSearch
End Sub
'<<==============


---
Regards,
Norman


"Jenny" wrote in message
...
Hi,
So, this is my button code, I keep getting error 9 on the 4th line:

Sub CommandButton1_Click()
Dim button1 As Module
Set button1 = Modules!["calc"]
CommandButton1.Caption = "refresh critical ratio table"
button1
End Sub

"calc" is the name of the module I need to access, within that
module
is a
sub procedure called "valuesearch" that needs to run on command.

Thanks!
"Norman Jones" wrote:

Hi Jenny,

Try posting your button code and, possibly, the function.

---
Regards,
Norman



"Jenny" wrote in message
...
I have 3 worksheets, 1 is results, 1 is calculation, and the 3rd
is
the
data
input interface. On the third I have buttons that need to
execute
and
update
field command. I can't get the button to work, when I run the
program
in
VBA
it can't find the function I am trying to call because it is a
different
module. I've tried sharing it, and making it public.... any
ideas?