Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 244
Default Refering to another module

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!


  #2   Report Post  
Posted to microsoft.public.excel.programming
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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 244
Default Refering to another module

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:

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!


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Calling worksheet module from other module. Michael Malinsky Excel Programming 2 December 14th 05 08:47 PM
code in module A to not execute a Worksheet_SelectionChange sub of another module Jack Sons Excel Discussion (Misc queries) 4 December 11th 05 11:52 PM
Run worksheet module code from workbook module? keithb Excel Programming 1 August 14th 05 04:04 AM
Calls from sheet module to ThisWorkbook module quartz[_2_] Excel Programming 2 June 23rd 05 03:37 PM
Variable from a sheet module in a class module in XL XP hglamy[_2_] Excel Programming 2 October 14th 03 05:48 PM


All times are GMT +1. The time now is 08:14 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"