Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Calling worksheet module from other module. | Excel Programming | |||
code in module A to not execute a Worksheet_SelectionChange sub of another module | Excel Discussion (Misc queries) | |||
Run worksheet module code from workbook module? | Excel Programming | |||
Calls from sheet module to ThisWorkbook module | Excel Programming | |||
Variable from a sheet module in a class module in XL XP | Excel Programming |