- 帖子
- 5923
- 主題
- 13
- 精華
- 1
- 積分
- 5986
- 點名
- 0
- 作業系統
- win10
- 軟體版本
- Office 2010
- 閱讀權限
- 150
- 性別
- 男
- 來自
- 台灣基隆
- 註冊時間
- 2010-5-1
- 最後登錄
- 2022-1-23
        
|
2#
發表於 2012-7-25 17:46
| 只看該作者
回復 1# user999 - Option Explicit
- Private Sub UserForm_Initialize()
- Dim LeftPos As Integer, TopPos As Integer, NewHeight As Integer, NewWidth As Integer, Rng As Range, H As Integer, i As Integer
- Dim NewOptionButton As MSForms.Control
- H = 1
- NewHeight = 15
- With Sheet1
- With .Columns(1)
- Set Rng = Sheet1.Range(.Cells(2), .Cells(2).End(xlDown))
- ComboBox1.List = Rng.Value
- End With
- With .Columns(2)
- Set Rng = Sheet1.Range(.Cells(2), .Cells(2).End(xlDown))
- NewWidth = (Frame2.Width - (Rng.Count * H)) / Rng.Count
- TopPos = (Frame2.Height - NewHeight) / 2
- For i = 1 To Rng.Count
- LeftPos = 1 * H + (i - 1) * NewWidth
- Set NewOptionButton = _
- Frame2.Controls.Add("forms.OptionButton.1")
- With NewOptionButton
- .Width = NewWidth
- .Caption = Rng.Cells(i)
- .Height = NewHeight
- .Left = LeftPos
- .Top = TopPos
- .AutoSize = True
- End With
- Next
- End With
- With .Columns(3)
- Set Rng = Sheet1.Range(.Cells(2), .Cells(2).End(xlDown))
- NewWidth = (Frame3.Width - (Rng.Count * H)) / Rng.Count
- TopPos = (Frame3.Height - NewHeight) / 2
- For i = 1 To Rng.Count
- LeftPos = 1 * H + (i - 1) * NewWidth
- Set NewOptionButton = _
- Frame3.Controls.Add("forms.CheckBox.1")
- With NewOptionButton
- .Width = NewWidth
- .Caption = Rng.Cells(i)
- .Height = NewHeight
- .Left = LeftPos
- .Top = TopPos
- .AutoSize = True
- End With
- Next
- End With
- End With
- End Sub
複製代碼 |
|