View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
OssieMac OssieMac is offline
external usenet poster
 
Posts: 2,510
Default ListBox Size and Screen Resolution

Hi Mike,

The following code sizes to the cell positions. I have assumed that you want
it to occur when the workbook is opened so have placed it in the
Workbook_Open event.

Not sure if you know how to do this but to install the code open the VBA
editor (Alt/F11) and double click ThisWorkbook in the Project explorer and
copy the code into it.

Note the comments where you may need to edit the code.



Note that a space and underscore at the end of a line is a line break in an
otherwise single line of code.

Private Sub Workbook_Open()
Dim objListBox As OLEObject
Dim dblLeft As Double
Dim dblTop As Double
Dim dblWidth As Double
Dim dblHeight As Double

'Edit "Sheet1" to your sheet name
With Sheets("Sheet1")
'Edit the ranges to suit the sizes you want.
'Note measurements are Left and Top of cells
dblLeft = .Range("C4").Left
dblTop = .Range("C4").Top
dblWidth = .Range("E8").Left _
- .Range("C4").Left

dblHeight = .Range("C15").Top _
- .Range("C4").Top
End With

'Edit "ListBox1" to your listbox name
Set objListBox = Sheets("Sheet1") _
.OLEObjects("ListBox1")
With objListBox
.Left = 47.25
.Top = 26.25
.Width = 97.5
.Height = 177.75
End With

End Sub

--
Regards,

OssieMac