我在Microsoft Word文档中有一些图表对象,我想使用VBA代码将其与中心对齐。什么是书面缺点似乎工作正常,因为它正确检测图形图表,但后来我不知道如何居中。
Sub CenterChart()
Dim n As Integer, i As Integer
Dim graf As Object
n = Application.ActiveDocument.InlineShapes.Count
If n <> 0 Then
For i = 1 To n
Set graf = Application.ActiveDocument.InlineShapes(i)
If graf.HasChart Then
'Here the code to align to center
Else
End If
Next i
End If
End Sub
由于您使用的是InlineShapes
格式化命令与文本相同 - 您使用居中的段落对齐方式。例如
If graf.HasChart Then
graf.Range.ParagraphFormat.Alignment = wdAlignParagraphCenter
Else
End If