List Box Sizing

raccoon588

Board Regular
Joined
Aug 5, 2016
Messages
118
is there anyway to loop through all my lists boxes and make them the same size when the excel file is opened?
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Where are the listboxes located?
 
Upvote 0
Thanks. I still have not figured out how to set width using vba in a loop to set width
Maybe someone else here will have a answer.

I can set nearly everything just not the Width.
 
Upvote 0
This script is what I have but I cannot figure out why when I try to set Width I get a error code:

Run Time Error 438
Object doesn't support this property or method.

Everything works if I remove .Width
Which is what your wanting.

Code:
Private Sub CommandButton1_Click()
'Modified  1/29/2019  1:02:41 PM  EST
Dim Lastrow As Long
Lastrow = Cells(Rows.Count, "A").End(xlUp).Row
    For Each OLEobj In ActiveSheet.OLEObjects
        If OLEobj.progID = "Forms.ListBox.1" Then
  
            With OLEobj.Object
                .Font.Size = 24
                .Clear
                .List = Range("A1:A" & Lastrow).Value
                .BackColor = vbGreen
                .ForeColor = vbRed
                .Width = 200
            End With
        End If
    Next OLEobj
End Sub
 
Upvote 0
It needs to be like
Code:
            With [COLOR=#ff0000]OLEobj[/COLOR]
                .[COLOR=#ff0000]Object[/COLOR].Font.Size = 24
                .[COLOR=#ff0000]Object[/COLOR].Clear
                .[COLOR=#ff0000]Object[/COLOR].List = Range("A1:A" & Lastrow).Value
                .[COLOR=#ff0000]Object[/COLOR].BackColor = vbGreen
                .[COLOR=#ff0000]Object[/COLOR].ForeColor = vbRed
                .Height = 200
                .Width = 200
            End With
 
Upvote 0
Thanks Fluff it works great now

It needs to be like
Code:
            With [COLOR=#ff0000]OLEobj[/COLOR]
                .[COLOR=#ff0000]Object[/COLOR].Font.Size = 24
                .[COLOR=#ff0000]Object[/COLOR].Clear
                .[COLOR=#ff0000]Object[/COLOR].List = Range("A1:A" & Lastrow).Value
                .[COLOR=#ff0000]Object[/COLOR].BackColor = vbGreen
                .[COLOR=#ff0000]Object[/COLOR].ForeColor = vbRed
                .Height = 200
                .Width = 200
            End With
 
Upvote 0

Forum statistics

Threads
1,213,551
Messages
6,114,273
Members
448,559
Latest member
MrPJ_Harper

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