格式化 Word 2016 table 单元格

Format Word 2016 table cell

在 Word 中开发计划工具,我为每个 session 培训课程使用 table。我想根据它们的列(每个有两种颜色选项)格式化单个单元格。出于布局目的,合并了一些标题行单元格。我希望我的用户在 "P" 标题下方的单元格上 right-click,然后 select activity 类型,然后 color-coded 作为单元格背景阴影。

因此我的 Range object returns 运行时错误 5992 就像 "As table has different number of columns, this collection does not offer access to individual columns"

Sub Makro2()
  Dim minCelle As Range
  Selection.SelectCell
  Set minCelle = Selection.Range
  minCelle.Text = minCelle.Columns.First.Index
  ' Here the error occurs. As a starting point, I want VBA to insert col#
End Sub

确定列号后,我就可以使用条件着色了。

我在 Word 2016 中工作,但如果可能的话,我想要一些向后兼容性。我在 MWE 上试用了它:一个 Word 2016 .docm 文档,其中包含一个 two-row、three-col table,其中两个单元格合并在第一行,并且包含一个带有上面的代码。

执行下面@CindyMeister 的更正,我得到了实际的列号。

Sub Makro2()
  Dim minCelle As Range
  Selection.SelectCell
  Set minCelle = Selection.Range
  minCelle.Text = Selection.Cells(1).ColumnIndex
End Sub