アクティブセルの横にシェイプを作成する
シート上の不要な既存のシェイプを削除します。
その後にテキストボックスを追加しています。
OLEObjects
チェクボックス・コンボボックスを作成するときは、このメソッドを使う必要があります。
コマンドボタン Forms.CommandButton.1 コンボボックス Forms.ComboBox.1 チェックボックス Forms.CheckBox.1 リストボックス Forms.ListBox.1 テキストボックス Forms.TextBox.1 スクロールバー Forms.ScrollBar.1 スピンボタン Forms.SpinButton.1 オプションボタン Forms.OptionButton.1 ラベル Forms.Label.1 イメージ Forms.Image.1 トグルボタン Forms.ToggleButton.1
Private Sub mySub()
Dim myDocument As Object
Dim Sp As Shape
Dim SpVal As String
Set myDocument = ActiveCell.Parent
SpVal = ActiveCell.Value
For Each Sp In myDocument.Shapes
If InStr(Sp.Name, "消したい名前") > 0 Then
Sp.Delete
End If
Next Sp
With myDocument.Shapes.AddTextbox(msoTextOrientationHorizontal, _
ActiveCell.Offset(0, 1).Left, _
ActiveCell.Offset(0, 1).Top, _
200, _
12)
.Name = "名前" & SpVal
.Placement = xlFreeFloating
With .TextFrame2
.TextRange.Text = "Here is some test text"
.MarginBottom = 0
.MarginLeft = 0
.MarginRight = 0
.MarginTop = 0
End With
End With
'チェックボックスを作成する場合は、OLEObjectsを使う必要があります。
With myDocument.OLEObjects.Add( _
ClassType:="Forms.CheckBox.1", _
Link:=False, _
DisplayAsIcon:=False, _
Left:=0, _
Top:=0, _
Width:=100, _
Height:=15)
.LinkedCell = ActiveCell.Offset(0, 1).Address
'略
End With
End Sub