Combobox code

Brawler

New Member
Joined
Jan 28, 2021
Messages
4
Office Version
  1. 365
Platform
  1. Windows
Hello,
Can someone help me figure out whats wrong with below code. Code does exactly what it shall, but still gives error on "property or method". The code creates a combobox with a listfillrange from another sheet.

Sub Object()
'
Dims1 = Range("b1").Value

'
ActiveSheet.OLEObjects.Add(ClassType:="Forms.ComboBox.1", Link:=False, DisplayAsIcon:=False, Left:=277.5, Top:=36.5, Width:=177.5, Height:=28).Select
With Selection
.ListFillRange = "Object!" & Dims1
.LinkedCell = "$V$7"
.DropDownLines = 8
.Display3DShading = False
End With

End Sub
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Remove these 2 lines.
VBA Code:
.DropDownLines = 8
.Display3DShading = False
 
Upvote 0
Thx. Did it.
If anyone still reads. Why is it that these "Selection" parameters gives fault?
 
Upvote 0
The problem might be with what Selection actually is.

If I print the TypeName of Selection when I run your code I get OLEObject and when I look up OLEObject in the Object Browser it doesn't have a either of the properties DropDownLines or Display3DShading.
 
Upvote 0
You might try it without selecting the control:

VBA Code:
WithActiveSheet.OLEObjects.Add(ClassType:="Forms.ComboBox.1", Link:=False, DisplayAsIcon:=False, Left:=277.5, Top:=36.5, Width:=177.5, Height:=28)
    .ListFillRange = "Object!" & Dims1
    .LinkedCell = "$V$7"
    .DropDownLines = 8
    .Display3DShading = False
End With
 
Upvote 0
Jon

I tried that, even threw in a few variables, but couldn't get it to work.

Also, I couldn't find anything for Display3DShading in the Object Browser.
 
Upvote 0
Jon

I tried that, even threw in a few variables, but couldn't get it to work.

Also, I couldn't find anything for Display3DShading in the Object Browser.
I didn't try it, my bad. But that should have helped if the Selection data type was strange.
 
Upvote 0

Forum statistics

Threads
1,215,053
Messages
6,122,882
Members
449,097
Latest member
dbomb1414

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