Refering to another module

A

Arne Hegefors

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!
 
T

tausif.mohammed

Arne said:
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
 
A

Arne Hegefors

Hello NickHK! Sorry for my late reply, been busy. Thank you very much for
your patient help, you save my life on a daily basis! My problem is that I
get different error messages when trying to run the code. Now I get "Object
does not support that method". I guess I mixed something up in the code but I
really do not know how to write it. The code works like this (it is basically
your code). First I have the loop that checks to see if it is a chart:

Sub arrayLoop()
Dim obj As Object
For Each obj In Selection
If TypeName(obj) = "ChartObject" Then
Call linjeDiagramKnapp(obj.Chart)
End If
Next
End Sub

after that I do the actual configurations of the chart(s).

Sub linjeDiagramKnapp(argChart As Object)
Dim mySize As Double
With argChart.Chart
.ApplyCustomType ChartType:=xlUserDefined, TypeName:="Standard"
With argChart.Chart
.Height = 150
......

I guess it is these last lines that the problem is to be found but I do not
know how to write it. I tried changing it on the basis of your reply but with
limited success. Please help me! Any help is very much appreciated and again
thank you very much for all your assistance!

"Arne Hegefors" skrev:
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top