PDA

View Full Version : Solved: Options into a combobox?



jamieCR9
10-18-2009, 04:54 AM
Hey, me again. :)

I was just wondering, if I had a slide with options to select, through check boxes, could I code the answers to appear in a combobox in another slide.

For example: Someone has the option to pick a bluray disc drive, an external mouse, a wireless router, a printer. Their results will either be none of the above, up to all four.

So, can I put their answers into a combobox instead of 4 labels? Thanks. :)

jamieCR9
10-20-2009, 09:13 AM
Okay so I have tried the following code, but everytime the powerpoint is run the options are all added on again. So I end up with the same options over and over and over again. The code is under a command button on a previous slide, which attempts to add their answers to the combobox. Know what I am doing wrong? Should it be a listbox?
Private Sub CommandButton1_Click()
If Slide16.ComboBox1.ListCount <= 4 Then
With Slide16.ComboBox1
If Slide13.CheckBox1.Value = True Then Slide16.ComboBox1.AddItem "Wireless Mouse - £25"
If Slide13.CheckBox2.Value = True Then Slide16.ComboBox1.AddItem "Canon Printer - £50"
If Slide13.CheckBox3.Value = True Then Slide16.ComboBox1.AddItem "Integrated Webcam - £30"
If Slide13.CheckBox4.Value = True Then Slide16.ComboBox1.AddItem "Blu Ray Drive - £60"
End With
End If
SlideShowWindows(1).View.GotoSlide (6)
End Sub
Sorry for the double post, just thought I'd get you guys more information.

John Wilson
10-20-2009, 12:01 PM
Try:

With Slide16.ComboBox1
.Clear
If Slide13.CheckBox1.Value = True Then .AddItem "Wireless Mouse - £25"
If Slide13.CheckBox2.Value = True Then .AddItem "Canon Printer - £50"
If Slide13.CheckBox3.Value = True Then .AddItem "Integrated Webcam - £30"
If Slide13.CheckBox4.Value = True Then .AddItem "Blu Ray Drive - £60"
End With

jamieCR9
10-20-2009, 03:10 PM
I tried that, but everytime you load the powerpoint it adds more and more and more, I only every want a minimum of 0 and maximum of 4 in the combobox. Will a listbox work better? Do you understand what I am asking by the way, sorry if it is a little sketchy.

EDIT: Okay yeah that works fine. Was wondering, does the list box list everything without a drop down menu? Maybe that is what I should be using instead, as I want to show them their choices, not give them another option per say. What do you think?

John Wilson
10-21-2009, 02:20 AM
If you just want to SHOW them their choices just use a normal ppt shape.
code would look like this (change text, slide number and shape number)

Dim strChoose As String
Private Sub CommandButton1_Click()

If Me.CheckBox1 = True Then strChoose = strChoose & "Wireless mouse" & vbCrLf
If Me.CheckBox2 = True Then strChoose = strChoose & "Canon printer" & vbCrLf
ActivePresentation.Slides(2).Shapes(3).TextFrame.TextRange = strChoose
End Sub

jamieCR9
10-21-2009, 10:50 AM
If you just want to SHOW them their choices just use a normal ppt shape.
code would look like this (change text, slide number and shape number)

Dim strChoose As String
Private Sub CommandButton1_Click()

If Me.CheckBox1 = True Then strChoose = strChoose & "Wireless mouse" & vbCrLf
If Me.CheckBox2 = True Then strChoose = strChoose & "Canon printer" & vbCrLf
ActivePresentation.Slides(2).Shapes(3).TextFrame.TextRange = strChoose
End Sub I'll let you know how it goes, thanks. :)

jamieCR9
10-21-2009, 11:35 AM
Dim strChoose As String
Private Sub CommandButton1_Click()
If Me.CheckBox1 = True Then strChoose = strChoose & "Wireless mouse" & vbCrLf
If Me.CheckBox2 = True Then strChoose = strChoose & "Canon printer" & vbCrLf
If Me.CheckBox3 = True Then strChoose = strChoose & "Webcam" & vbCrLf
If Me.CheckBox4 = True Then strChoose = strChoose & "Blu Ray Drive" & vbCrLf
ActivePresentation.Slides(16).Shapes(1).TextFrame.TextRange = strChoose
End Sub
That is what I have, but there is an error with the bottom line. Is that the slide index number or the slideID, as in the VBA slide number? Also, how do I know what number a regular shape is? :(

I really do appreciate the help, just trying to add finishing touches.

John Wilson
10-21-2009, 03:17 PM
The Slides(xx) should be the index ie Slides (16) is the sixteenth slide in the presentation. The slide object number (what you are calling the vba number I think) is usually the sixteenth slide added to the presentation often not the same thing.

The easiest way to get the shape number in pre 2007 is to give it an animation the name (eg rectangle 4) in the animation pane will indicate the number. In 2007 the selection pane will indicate where the shape comes in the order. Alternatively select the shape and run this code which will work in all versions.

MsgBox ActiveWindow.Selection.ShapeRange(1).ZOrderPosition

Be aware that if you delete shapes or move shapes back or forwards the number may change.

jamieCR9
10-21-2009, 04:29 PM
No longer relevent...

[Can't find delete button?]

jamieCR9
10-21-2009, 05:25 PM
Right only one problem now, that is the same as what happened with the original combobox. Every time you press the command button the values are added over and over again. Code:
Dim strChoose As String
Private Sub CommandButton1_Click()
If Me.CheckBox1 = True Then strChoose = strChoose & "Wireless mouse" & vbCrLf
If Me.CheckBox2 = True Then strChoose = strChoose & "Canon printer" & vbCrLf
If Me.CheckBox3 = True Then strChoose = strChoose & "Webcam" & vbCrLf
If Me.CheckBox4 = True Then strChoose = strChoose & "Blu Ray Drive" & vbCrLf
ActivePresentation.Slides(16).Shapes("myshape").TextFrame.TextRange = strChoose
End Sub
You really are a legend mate!

John Wilson
10-22-2009, 02:14 AM
My mistake and yes naming the shape is good!


Private Sub CommandButton1_Click()
Dim strChoose As String 'sets to no text
If Me.CheckBox1 = True Then strChoose = strChoose & "Wireless mouse" & vbCrLf
If Me.CheckBox2 = True Then strChoose = strChoose & "Canon printer" & vbCrLf
If Me.CheckBox3 = True Then strChoose = strChoose & "Webcam" & vbCrLf
If Me.CheckBox4 = True Then strChoose = strChoose & "Blu Ray Drive" & vbCrLf
ActivePresentation.Slides(16).Shapes("myshape").TextFrame.TextRange = strChoose
End Sub

jamieCR9
10-22-2009, 10:51 AM
My mistake and yes naming the shape is good!


Private Sub CommandButton1_Click()
Dim strChoose As String 'sets to no text
If Me.CheckBox1 = True Then strChoose = strChoose & "Wireless mouse" & vbCrLf
If Me.CheckBox2 = True Then strChoose = strChoose & "Canon printer" & vbCrLf
If Me.CheckBox3 = True Then strChoose = strChoose & "Webcam" & vbCrLf
If Me.CheckBox4 = True Then strChoose = strChoose & "Blu Ray Drive" & vbCrLf
ActivePresentation.Slides(16).Shapes("myshape").TextFrame.TextRange = strChoose
End Sub Thanks for everything. :) A little off the same topic, but is there any code which you can put under a command button which resets all the VBA user textbox/option button value/checkbox values entries, leaving all the text boxes empty etc. for the next user of the powerpoint?

jamieCR9
10-23-2009, 05:25 PM
Since I can't edit my last post, all I need is the code to end the powerpoint. I tried to work it out/find it, but I can't see where it is. I don't want to have to use the action button, as I would rather the command button on the last slide run the function.

John Wilson
10-25-2009, 05:20 AM
SlideShowWindows(1).View.Exit ?

jamieCR9
10-25-2009, 05:25 AM
SlideShowWindows(1).View.Exit ?
Tried SlideShowWindows(1).View.EndNamedShow, as the exit one didn't come up, and mine didn't work either. :rotlaugh:

John Wilson
10-25-2009, 10:33 AM
EndNamedShow is for Custom Shows it's Exit!

jamieCR9
10-25-2009, 10:37 AM
I fail at life, thanks John.