PDA

View Full Version : Solved: on open show combobox with 10 choices



karognigni
09-01-2011, 07:49 AM
I'm running XP, SP3.
I'm running Xcel 2000 9.0.2812 (yeah i know, i know).
I'm trying to do this via VBA.
I would like to click on a Xcel file stored in my network.
I would like this files opens and automatically shows a Combobox filled with 10 choices, stored in the combobox, not referring to cells.
I would like to choose one of the choices and by consequence run a macro, without an action button to press.
In the end, 10 choices in combobox, 10 consequent macros, running as the choice is made.
The action of the macro should be to deactivate the sheet protection, apply a customized view, and reactivate the sheet protection.
I've tried thousands of ways, no solution.
Is this really impossible?
If no, can you send me a code and where to write it?
Many thanks.
Ale

CatDaddy
09-01-2011, 09:09 AM
Workbook_Open event in private module of Workbook object ThisWorkbook will trigger a macro upon opening...maybe you tried this already but it should work

Aussiebear
09-01-2011, 04:05 PM
Please attach a sample workbook with what you require. The sample workbook should contain a before and after result where possible. To attach a workbook, click on Go Advanced, scroll down to Manage Attachments and follow the directions from there.

karognigni
09-02-2011, 12:34 AM
Ok this is the sample workbook and this is a BEFORE situation.
If you see, there is a combobox actrually doing nothing.
Then you can also see 10 macros in sheet 1 already prepared to set 10 different personalized views.
I'm trying to do this:
The Combobox should show 10 chioices that once choosed, launch a respective macro of the 10 already written.
Hope i've explained clearly.

Any help?

Thanks.

Ale

karognigni
09-02-2011, 03:19 AM
Thanks CatDaddy, but one of the trouble using the code:

Private Sub Workbook_Open()

ActiveSheet.OLEObjects.Add ClassType:="Forms.ComboBox.1"

End Sub

located in ThisWorkbook, is that each time you open the file, this generates a brand new Combobox, while instead should be always the same one.

Thanks.

Ale

Aussiebear
09-02-2011, 03:39 AM
Private sub Workbook_Open()
Me.Combobox.1.Show
End Sub

karognigni
09-02-2011, 03:46 AM
Thanks Aussiebear, this generates a Sintax Error.

Ale

Kenneth Hobs
09-02-2011, 06:42 AM
In ThisWorkbook object:
Private Sub Workbook_Open()
ComboBox1Activate
End Sub

In your Module or another:
Sub ComboBox1Activate()
With Foglio1.ComboBox1
.MatchRequired = True
If .ListCount <> 11 Then
.Clear
Dim i As Integer
.AddItem "", 0
For i = 1 To 10
.AddItem "SAL" & i, i
Next i
End If
.ListIndex = 0
.Activate
End With
End Sub

In the object by double clicking in Developer mode or right click the sheet tab, View Code and paste:
Private Sub ComboBox1_Change()
If ComboBox1.ListIndex > 0 Then Application.Run ComboBox1.Value
End Sub

karognigni
09-03-2011, 02:18 AM
Mr. Kenneth Hobs, i knew here inside i would have found a genius.

No idea how to thank you.

That's perfect.

Many thanks.

Ale