以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  VBA表格垂直居中和水平居中  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=175656)

--  作者:xluoping
--  发布时间:2022/3/14 14:36:00
--  VBA表格垂直居中和水平居中
with doc.tables(1)
      .Range.ParagraphFormat.Alignment = msword.WdParagraphAlignment.wdAlignParagraphCenter
      .Range.Cells.VerticalAlignment = msword.WdParagraphAlignment.wdCellAlignVerticalCenter
end with

以上代码报错,是什么原因?

--  作者:有点蓝
--  发布时间:2022/3/14 14:49:00
--  
        With doc.Tables(1)
            .Range.ParagraphFormat.Alignment = msword.WdParagraphAlignment.wdAlignParagraphCenter
            .Range.Cells.VerticalAlignment = msword.WdCellVerticalAlignment.wdCellAlignVerticalCenter
        End With