shijian123 发表于 2018-12-23 17:59:34

vba 代码如何让p p t的文本框居中

如题,如何使用vba将文本框或图片居中
我是这样写的,.TextFrame2.HorizontalAnchor = msoAnchorCenter 无效

Set newSlide = pptthis.slides.Add(2, 12)
With newSlide.Shapes.AddTextbox(msoTextOrientationHorizontal, 200, 230, 700, 100)
' .TextFrame.TextRange.Font.Color = vbRed
.TextFrame.TextRange.Text = “pptname”
.TextFrame.TextRange.Font.Size = 40
' .TextFrame.TextRange.Font.name = "微软雅黑"
' .TextFrame.TextRange.Font.NameAscii = "微软雅黑"
' .TextFrame.TextRange.Font.NameOther = "微软雅黑"
.TextFrame.TextRange.Font.NameFarEast = "微软雅黑"
.TextFrame.TextRange.Font.Bold = msoTrue
.TextFrame.HorizontalAnchor = msoAnchorCenter
.TextFrame2.HorizontalAnchor = msoAnchorCenter


End With

excel0000 发表于 2018-12-23 20:54:15

自己顶一个

tswhxb 发表于 2018-12-23 21:02:20

你是想让文本框或图片在舞台页面上左右居中或上下居中吗?若是,请参考以下代码:
Sub 相对页面水平居中()
    On Error Resume Next
    Dim paw%, shw% '页面宽,图形宽
    Dim oShape As PowerPoint.Shape   
    If ActiveWindow.Selection.type = ppSelectionNone Then Exit Sub   
    paw = ActivePresentation.PageSetup.SlideWidth    '磅
    For Each oShape In ActiveWindow.Selection.ShapeRange
      shw = oShape.Width
      oShape.Left = (paw - shw) / 2
    Next
End Sub
页: [1]
查看完整版本: vba 代码如何让p p t的文本框居中