How do I access an excel macro in visual basic?


Posted by Geoff on May 22, 2000 6:22 AM

Is it possible to access an excel macro (dropdown list) in visual basic? and if so, can I enable/disable the macro? What I have is a dropdown list macro in excel and an ActiveX radio button and when the radio button is checked, I want to enable the dropdown list macro. I cannot change the dropdown list macro to an ActiveX control. Any ideas?

Posted by Geoff on May 22, 2000 8:37 AM

Sorry, I meant a form control

Sorry, I must've been dreaming of macros earlier.

Posted by Ivan Moala on May 22, 2000 2:10 PM

Re: Sorry, I meant a form control


Hi Geoff

You can't disable it, BUT you could try changing the
Droplists settings eg

Sub EableFormDroplistCtrl()
ActiveSheet.Shapes("Drop Down 1").Select
With Selection
.ListFillRange = "$A$1:$A$10"
.LinkedCell = "$B$1"
.DropDownLines = 8
End With
End Sub

Sub DisableFormDroplistCtrl()
ActiveSheet.Shapes("Drop Down 1").Select
With Selection
.ListFillRange = ""
.LinkedCell = ""
.DropDownLines = 1
End With
End Sub


this should get you going


Ivan

Posted by Geoff on May 23, 2000 4:40 AM

Re: Sorry, I meant a form control

Ivan, thanks for the help. I'm getting one problem though. In your code, during runtime, on the line .ListFillRange = "some range", it's giving me this error "Unable to set the ListFillRange property of the DropDown class". I'm sure I'm not doing something right but I can't seem to figure it out. I triple checked my code and it looks good. Any thoughts?

Geoff

Posted by Ivan Moala on May 23, 2000 5:31 AM

Re: Sorry, I meant a form control

Geoff

It worked for me, what is the code you are using
Can you post.
have you selected the button ??

Thanks


Ivan

Posted by Geoff on May 23, 2000 5:48 AM

Re: Sorry, I meant a form control

It worked for me, what is the code you are using

Sure, but here's a little more detail on the problem first. I have two drop down lists that get their listitems from another sheet. Each list has a corresponding ActiveX radio button that goes with them. When their radio button is checked, the list is (using your idea) filled with items and the opposing list is cleared of items. Okay, here is my code and the variable RemoveList is just a string name of which list to "remove" or clear. Also, the two drop boxes are Drop Down 52 and Drop Down 56. This function is called from my click action event of either of the two radio buttons. You know how the dot operator produces a menu with a list of variables and methods you can use? Well, when I do a ActiveSheet.something, no menu appears so maybe that has something to do with it. Thanks again Ivan.

Private Function AlterDropLists(RemoveList As String)
If RemoveList = "Europe" Then
ActiveSheet.Shapes("Drop Down 52").Select
With Selection
.ListFillRange = ""
.LinkedCell = ""
.DropDownLines = 14
End With

ActiveSheet.Shapes("Drop Down 56").Select
With Selection
.ListFillRange = "Calcs!$J$1:$J$52"
.LinkedCell = "Calcs!$J$54"
.DropDownLines = 14
End With
ElseIf RemoveList = "US" Then
ActiveSheet.Shapes("Drop Down 56").Select
With Selection
.ListFillRange = ""
.LinkedCell = ""
.DropDownLines = 14
End With

ActiveSheet.Shapes("Drop Down 52").Select
With Selection
.ListFillRange = "Calcs!$G$1:$G$14"
.LinkedCell = "Calcs!$G$16"
.DropDownLines = 14
End With
End If
End Function



Posted by Ivan Moala on May 23, 2000 6:14 PM

Re: Sorry, I meant a form control

Hi Geoff
Thanks for the code.
I should have tweak earlier when you were using
activex button !!

Go into edit mode then
For each of your activex buttons,
select it and right click to get the properties.
For the property "TakeFocusonclick" select False
Do this for each one. this should clearup your problem.


Ivan