Vba 在Word中整行水平对齐单元格内容

Vba 在Word中整行水平对齐单元格内容,vba,ms-word,Vba,Ms Word,基本上,想要选择一行并将每个单元格的内容居中对齐,但似乎无法使其正常工作。什么都不做: For r = 1 To rCount wd.ActiveDocument.Tables(c).Cell(r, 1).Select textVal = wd.Selection.Text If textVal Like "Job*" Then wd.Selection.Font.Allcaps = True wd.ActiveDocument.Table

基本上,想要选择一行并将每个单元格的内容居中对齐,但似乎无法使其正常工作。什么都不做:

For r = 1 To rCount
    wd.ActiveDocument.Tables(c).Cell(r, 1).Select
    textVal = wd.Selection.Text
    If textVal Like "Job*" Then
        wd.Selection.Font.Allcaps = True
        wd.ActiveDocument.Tables(c).Rows(r).Alignment = wdAlignRowCenter
    End If
Next
wd.ActiveDocument.Tablesc.Rowsr.Alignment=wdAlignRowCenter似乎只是在讨论在页面上对齐的行本身,而不是内容。我可以在单个单元格中找到文档,但不能在整行中找到


有什么建议吗?

您需要更改段落格式,而不是表格对齐方式:

With wd.ActiveDocument.Tables(c)
  For r = 1 To .Rows.Count
    With .Cell(r, 1)
      If InStr(.Range.Text, "Job") = 1 Then
        .Range.Font.AllCaps = True
        .Row.Range.ParagraphFormat.Alignment = wdAlignParagraphCenter
      End If
    End With
  Next
End With
也请注意,不需要选择任何内容