Results 1 to 8 of 8

Thread: [RESOLVED] Call ComboBox

  1. #1
    New Member
    Join Date
    Aug 12
    Posts
    5

    Resolved [RESOLVED] Call ComboBox

    Help
    I'm quite new to this and need help with the combobox.
    How do i tell the combobox which module that has called it?
    Want the combo selection to work on different shapes.
    Name:  Color change.JPG
Views: 93
Size:  363.5 KB
    Tusen takk på forhånd

  2. #2
    New Member
    Join Date
    Aug 12
    Posts
    5

    Re: Call ComboBox

    New picture:
    Name:  Color change.JPG
Views: 70
Size:  166.6 KB

  3. #3
    New Member
    Join Date
    Aug 12
    Posts
    5

    Re: Call ComboBox

    Try this instead:

    Private Sub UserForm_Activate()

    ComboBox1.AddItem "Item 1"
    ComboBox1.AddItem "Item 2"
    ComboBox1.AddItem "Item 3"
    ComboBox1.AddItem "Item 4"
    ComboBox1.Text = "Velg Riser"
    End Sub



    Private Sub ComboBox1_Click()
    If Oval2 Then
    If ComboBox1.Text = "Item 1" Then
    Sheet1.Shapes("Oval 2").Fill.ForeColor.RGB = vbGreen

    ElseIf ComboBox1.Text = "Item 2" Then
    Sheet1.Shapes("Oval 2").Fill.ForeColor.RGB = vbBlue
    End If
    ElseIf Oval4 Then
    If ComboBox1.Text = "Item 1" Then
    Sheet1.Shapes("Oval 4").Fill.ForeColor.RGB = vbGreen

    ElseIf ComboBox1.Text = "Item 2" Then
    Sheet1.Shapes("Oval 4").Fill.ForeColor.RGB = vbBlue
    End If
    End If

    Have two shapes called oval 2 and 4 and want to change colour on those depending of which shape i'm clicking on

    End Sub

  4. #4
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 02
    Location
    Bristol, UK
    Posts
    35,554

    Re: Call ComboBox

    Welcome to VBForums

    Thread moved to the 'Office Development/VBA' forum... note that while it certainly isn't made clear, the "VB Editor" in Office programs is actually VBA rather than VB, so the 'VB6' forum is not really apt

  5. #5
    PowerPoster
    Join Date
    Dec 04
    Posts
    18,522

    Re: Call ComboBox

    let me see if i understand what you want

    you want to click an oval, then select a color from the combobox?
    the oval is on a worksheet, not a userform?
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  6. #6
    New Member
    Join Date
    Aug 12
    Posts
    5

    Re: Call ComboBox

    That's right.
    Have several ovals on the worksheet and want's to use the same combo box when I click on them.
    Need some code to tell the which oval to perfom the change.
    If I click on oval 2 I want the colour on oval 2 to change when and when I click oval 4 I want oval 4 to change.
    The code works ,but how to tell which oval that called the userform?
    Thanks

  7. #7
    Fanatic Member
    Join Date
    Oct 08
    Location
    Midwest Region, United States
    Posts
    986

    Re: Call ComboBox

    Here is some code to show how to determine which oval initiated the action. It doesn't do what you're asking, but should give you an idea how to proceed. You need to run it by clicking an oval; it won't work if you simply step through it in the editor.

    Code:
    Sub ovals()
        Dim wb As Workbook
        Dim ws As Worksheet
        Dim shpName As String
        Dim shp As Shape
        
        Set wb = Workbooks("ovals kurt.xlsm")   'your workbook name here
        Set ws = wb.Sheets("sheet1")            'your sheet name here
        
        shpName = ws.Shapes(Application.Caller).Name
        
        Set shp = ws.Shapes(shpName)
        
        shp.Left = shp.Left + 10   'moving the "calling" shape to demonstrate
    
    End Sub

  8. #8
    New Member
    Join Date
    Aug 12
    Posts
    5

    Re: Call ComboBox


    Thanks,just what I needed........

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •