Excel 2011 for Mac - VBA - Form Control Combo Box - Return Selected Value

jarrah

New Member
Joined
May 1, 2013
Messages
28
Hello,

I have a macro that needs to work on both Windows (Excel 2010) and Macs (Excel 2011), but I'm having problems with the Combo Box.

On Windows the following code works fine:

Code:
    On Error Resume Next
    With wsTK.Shapes("month").ControlFormat
        selMonth = .List(.Value)
    End With
    On Error GoTo 0
    If selMonth = 0 Then
        MsgBox "Please select a month from the drop-down box"
        Exit Sub
    End If

However on a Mac it doesn't return the selected value to "selMonth" and so as this variable is empty, it displays the msgbox and exits the sub.

Would someone be able to help find a solution as I've been Googling for the past hour with no luck.

Thanks.
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Hoping to catch someone in the evening with my question before it disappears off the first page. :)

Thanks.
 
Upvote 0
I eventually found the problem - basically the Mac version of office doesn't like passing worksbooks/worksheets as a variable to ControlFormat.

I basically have to set the worksheet name as it won't accept a variable:

Code:
With Worksheets("Sheet1").Shapes("month").ControlFormat
        wbkName2 = .List(.Value)
End With
instead of
Code:
wsTK = worksheets("Sheet1")

With wsTK.Shapes("month").ControlFormat 
    selMonth = .List(.Value) 
End With
On a different but similar note, this code to detect an option button works ok on a Mac and Windows
Code:
If wsTK.OptionButtons("option1").Value = 1 Then
      msgbox "You have chosen x option"
end if

The problem also happens with Check Boxes, so is there a command similar to "OptionButtons" for Check Boxes that would work like below because it seems "ControlFormat" is the issue here?

Code:
if wsTK.checkbox("checkbox1").value = 1 then call function1
Instead of
Code:
if worksheets("Sheet1").shapes("checkbox1").controlFormat.value = 1 then call function1
Thanks.
 
Upvote 0

Forum statistics

Threads
1,223,728
Messages
6,174,150
Members
452,548
Latest member
Enice Anaelle

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top