View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
[email protected] tausif.mohammed@gmail.com is offline
external usenet poster
 
Posts: 3
Default Refering to another module


Arne Hegefors wrote:
I have a small problem with a macro. I have two different moduls in my code.
In module1 i have the code for some buttons and so and in module2 i have the
code for what happens if i press the buttons. However my code has trouble
finding the different modules and I need help on how to write this properly.
Code in module1:

Sub Create_Menu()
Dim MyBar As CommandBar
Dim MyPopup As CommandBarPopup
Dim button1 As CommandBarButton
.....
Set button1 = .Controls.Add(Type:=msoControlButton)
With button1
.Caption = "Button!"
.BeginGroup = True
.OnAction = "button1_Click"

and in modul2:

Sub button1_Click()
Dim objChart As ChartObject


Now I need help with how to refer to the sub. My code is quite messy if i
have to have it in the same module so it would be prefect it that was
possible. Thanks very much in advance!


Hi Arne ..

In module 1 .. where you use the .OnAction property .. use the module
name as well.

eg ) Sub Create_Menu()
Dim MyBar As CommandBar
Dim MyPopup As CommandBarPopup
Dim button1 As CommandBarButton
.....
Set button1 = .Controls.Add(Type:=msoControlButton)
With button1
.Caption = "Button!"
.BeginGroup = True
.OnAction = "Module2.button1_Click"


I think this shld solve your problem

cheers