半角チルダ

ExcelVBA、その他。
覚え書きや、補足資料などのスクラップブック。
end-u(1037781)

■VBA VBComponents.Add(vbext_ct_MSForm)

2010-12-06 21:00:00 | scrap
#しつこいようだけど
[Visual Basic プロジェクトへのアクセスを信頼する]必要あり。


Sub try() '「WebBrowserを20コ配置したUserFormを作成」するコード
  Const vbext_ct_MSForm As Long = 3
  Const mgn As Single = 2  '調整余白
  Const w  As Single = 100 'WebBrowser.Width|Height
  Const h  As Single = 20 'CommandButton.Height
  Dim iw  As Single
  Dim ih  As Single
  Dim i   As Long

  On Error GoTo extLine
  With ActiveWorkbook.VBProject.VBComponents.Add(vbext_ct_MSForm)
    iw = .Properties("Width") - .Properties("InsideWidth")
    ih = .Properties("Height") - .Properties("InsideHeight")
    .Properties("Width") = iw + mgn + w + mgn
    .Properties("Height") = ih + mgn + w + mgn + h + mgn
    With .Designer.Controls
      For i = 1 To 20
        With .Add("Shell.Explorer.2")
          .Left = mgn
          .Top = mgn
          .Width = w
          .Height = w
        End With
      Next
      With .Add("Forms.CommandButton.1")
        .Left = mgn
        .Top = mgn + w + mgn
        .Width = w
        .Height = h
      End With
    End With
  End With

extLine:
  With Err()
    If .Number <> 0 Then
      MsgBox .Number & "::" & .Description
    End If
  End With
End Sub

■UserForm作成コードで既出。
#一応、次回記事のネタフリで :D
Comment
  • X
  • Facebookでシェアする
  • はてなブックマークに追加する
  • LINEでシェアする