(祝)東京オリンピック!

(祝)北京オリンピック!

SHAPE関係

アクティブセルの横にシェイプを作成する

シート上の不要な既存のシェイプを削除します。
その後にテキストボックスを追加しています。

AddShapeメソッド

図形の四角(レクタングル)方法があります。

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

COPY

  1. Private Sub mySub()
  2. Dim myDocument As Object
  3. Dim Sp As Shape
  4. Dim SpVal As String
  5. Set myDocument = ActiveCell.Parent
  6. SpVal = ActiveCell.Value
  7. For Each Sp In myDocument.Shapes
  8. If InStr(Sp.Name, "消したい名前") > 0 Then
  9. Sp.Delete
  10. End If
  11. Next Sp
  12.  
  13. With myDocument.Shapes.AddTextbox(msoTextOrientationHorizontal, _
  14. ActiveCell.Offset(0, 1).Left, _
  15. ActiveCell.Offset(0, 1).Top, _
  16. 200, _
  17. 12)
  18. .Name = "名前" & SpVal
  19. .Placement = xlFreeFloating
  20. With .TextFrame2
  21. .TextRange.Text = "Here is some test text"
  22. .MarginBottom = 0
  23. .MarginLeft = 0
  24. .MarginRight = 0
  25. .MarginTop = 0
  26. End With
  27. End With
  28.  
  29. 'チェックボックスを作成する場合は、OLEObjectsを使う必要があります。
  30. With myDocument.OLEObjects.Add( _
  31. ClassType:="Forms.CheckBox.1", _
  32. Link:=False, _
  33. DisplayAsIcon:=False, _
  34. Left:=0, _
  35. Top:=0, _
  36. Width:=100, _
  37. Height:=15)
  38. .LinkedCell = ActiveCell.Offset(0, 1).Address
  39. '略
  40. End With
  41.  
  42. End Sub