' コマンドバー上に、オープンしているブックのシート名を表示するコンボボックスを作成する。
Sub combobox_add()
' ツールバー上にコンボボックスを追加する。
'オープンしているブックのシート名をシート上に書き出す。
Call name_write
'このマクロがあるブックのシート1をアクティブにする。
ThisWorkbook.Sheets("sheet1").Activate
'シート名が指定のセルに無かったら、終了する。
If Range("a5").Value = "" Then
MsgBox "開くシート名が表示されていません。"
End
End If
'セルに書き出した該当シートが無かったら、エラーになるので、
'その場合は、何もしないで、終了する。
On Error GoTo ex
Dim i As Integer
Dim j As Integer
Dim taitoru As String
'セルに書き出したシート名の数を変数jに格納する。
j = Range("a5").CurrentRegion.Rows.Count
'コマンドバーを追加する。
Dim mybar
Set mybar = CommandBars _
.Add(Name:="open", Position:=msoBarTop, _
Temporary:=True)
'追加したコマンドバーにボタンを追加する。
'ID3-->上書きボタンと共に。
With mybar
.Controls.Add Type:=msoControlButton, Id:=3
.Visible = True
End With
'追加したコマンドバーにコンボボックスを追加する。
Dim Newcbox
Set Newcbox = CommandBars("open").Controls.Add(Type:=msoControlComboBox)
With Newcbox
.Caption = "combo1"
'そのコンボボックスに値を代入する。
For i = 1 To j
taitoru = Range("a" & i + 4).Text & "_" & Range("b" & i + 4).Text & "__" & Range("c" & i + 4).Text
.AddItem taitoru, i
Next
'コンボボックスの値を選択したときのアクションを定義する。
.OnAction = "sheet_act"
' .Text = .List(1)
End With
'コマンドバーの幅、ドロップダウンしたときの幅と高さを定義する。
With CommandBars("open").Controls("combo1")
.Width = 280
.DropDownWidth = 320
' .Style = msoComboLabel
.DropDownLines = 20
End With
'ff更新というボタンを追加し、アクションを定義する。
Dim Kousin
Set Kousin = CommandBars("open").Controls.Add(Type:=msoControlButton)
With Kousin
.Caption = "ff更新"
.OnAction = "kousin"
.Style = msoButtonCaption
End With
ex:
End Sub