VBA Worksheet Combobox Font color setting

pingme89

Board Regular
Joined
Jan 23, 2014
Messages
176
Office Version
  1. 365
Platform
  1. Windows
I have the following code which programmatically adds a combobox to a worksheet.
VBA Code:
    Set Cell = WSD.Range("J2")
    WSD.OLEObjects.Add(ClassType:="Forms.ComboBox.1", link:=False, _
    DisplayAsIcon:=False, Left:=Cell.Left - 5, Top:=Cell.Top + 3, Width:=Cell.Width + 125, Height:=Cell.Height).Name = "cboSTORESELECTION" & SheetName
    With WSD.Shapes("cboSTORESELECTION" & SheetName).OLEFormat
        .Object.LinkedCell = "$J$2"
        .Object.ListFillRange = "CCStoreName"
    End With
    Set objOle = WSD.OLEObjects("cboSTORESELECTION" & SheetName)
    objOle.Object.Font.Size = 13
    objOle.Object.ListRows = 14
    objOle.Object.SpecialEffect = 0 '"0 - fmSpecialEffectFlat"
    Set objOle = Nothing

This works fine, however, I want to be able to set the font color to Blue programmatically but I am not sure how to do this.
I can manually go into the properties of the combobox to change it so I am assuming there is also a way to do it with VBA.
I hope someone can offer me some advice.

Thanks.
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Just add line ForeColor

VBA Code:
Set cell = WSD.Range("J2")
WSD.OLEObjects.Add(ClassType:="Forms.ComboBox.1", link:=False, _
DisplayAsIcon:=False, Left:=cell.Left - 5, Top:=cell.Top + 3, Width:=cell.Width + 125, Height:=cell.Height).Name = "cboSTORESELECTION" & SheetName
With WSD.Shapes("cboSTORESELECTION" & SheetName).OLEFormat
    .Object.LinkedCell = "$J$2"
    .Object.ListFillRange = "CCStoreName"
End With
Set objOLE = WSD.OLEObjects("cboSTORESELECTION" & SheetName)
With objOLE
    .Object.Font.Size = 13
    .Object.ListRows = 14
    .Object.SpecialEffect = 0 '"0 - fmSpecialEffectFlat"
    .Object.ForeColor = vbBlue
End With
Set objOLE = Nothing
 
Upvote 0
Solution
Just add line ForeColor

VBA Code:
Set cell = WSD.Range("J2")
WSD.OLEObjects.Add(ClassType:="Forms.ComboBox.1", link:=False, _
DisplayAsIcon:=False, Left:=cell.Left - 5, Top:=cell.Top + 3, Width:=cell.Width + 125, Height:=cell.Height).Name = "cboSTORESELECTION" & SheetName
With WSD.Shapes("cboSTORESELECTION" & SheetName).OLEFormat
    .Object.LinkedCell = "$J$2"
    .Object.ListFillRange = "CCStoreName"
End With
Set objOLE = WSD.OLEObjects("cboSTORESELECTION" & SheetName)
With objOLE
    .Object.Font.Size = 13
    .Object.ListRows = 14
    .Object.SpecialEffect = 0 '"0 - fmSpecialEffectFlat"
    .Object.ForeColor = vbBlue
End With
Set objOLE = Nothing
OMG. I feel stupid now.... Too much copy and pasting without thinking. Thanks. I needed a fresh pair of eyes.
 
Upvote 0
Learning never ends. I also did many dumb mistakes. ;)
 
Upvote 0

Forum statistics

Threads
1,223,886
Messages
6,175,198
Members
452,616
Latest member
intern444

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