0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Word VBA キャンバス内の図を操作

Last updated at Posted at 2021-08-17

新しい描画キャンバス作成

挿入>図形>新しい描画キャンバス作成

サンプルコード説明

  • 選択中の描画キャンバス内にある「Rectangle」の図形に対して
  • 幅:30mm
  • 高さ:10mm
  • フォントサイズ:8p
  • 図形内フォント水平/垂直軸:配置中央
  • フォントネーム:MS Pゴシック
  • 図形内上下左右:余白0p
  • 行間:固定7p
sample.docm
Sub startMoldShapes()
    Dim itemMax As Long
    Dim itemName As String
    Dim pageName As String
    Dim ans As Boolean

pageName = Selection.ShapeRange(1).Name
ans = MsgBox("OK?", vbYesNo)
If ans = False Then End
itemMax = ActiveDocument.Shapes(pageName).CanvasItems.Count

For i = 1 To itemMax
    itemName = ActiveDocument.Shapes(pageName).CanvasItems(i).Name

    
    If itemName Like "*Rectangle*" Then
        With ActiveDocument.Shapes(pageName).CanvasItems(i)
            .Width = MillimetersToPoints(30)
            .Height = MillimetersToPoints(10)
            .TextFrame.TextRange.Font.Size = 8
            .TextFrame.HorizontalAnchor = msoAnchorCenter
            .TextFrame.VerticalAnchor = msoAnchorMiddle
            .TextFrame.TextRange.Font.Name = "MS Pゴシック"
            .TextFrame.MarginTop = 0
            .TextFrame.MarginBottom = 0
            .TextFrame.MarginRight = 0
            .TextFrame.MarginLeft = 0
        End With
        
        ActiveDocument.Shapes(pageName).CanvasItems(i).Select
        With Selection.ParagraphFormat
            .LineSpacingRule = wdLineSpaceExactly
            .LineSpacing = 7
        End With
    End If
Next
            
End Sub
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?