[英]VBA Word inputting into nested cells
Im looking to input text into nested cells in word using VBA. 我希望使用VBA将文本输入到单词的嵌套单元格中。 I can input into the top level table using the code below but can't input into a nested cell.
我可以使用下面的代码输入顶级表,但不能输入嵌套的单元格。 (There are multiple nested tables).
(有多个嵌套表)。
Any help on how to do this? 有什么帮助吗?
ActiveDocument.Tables(1).Cell(Row:=23, Column:=19).Range.Text = "" ActiveDocument.Tables(1).Cell(Row:= 23,Column:= 19).Range.Text =“”
You have to test for nested cells and then point to the appropriate cell range. 您必须测试嵌套单元格,然后指向适当的单元格范围。 Here is an example.
这是一个例子。
If Selection.Cells(1).NestingLevel = 2 Then
Selection.Cells(1).Range.Cells(1).Range.Text = "Nested"
Else
Selection.Cells(1).Range.Text = "Not Nested"
End If
Using your example of a table that contains a nested table cell in Row 23, Column 19 the command will look like the following. 使用第23列第19列中包含嵌套表格单元格的表格示例,该命令将如下所示。
ActiveDocument.Tables(1).Cell(23, 19).Range.Cells(1).Range.Text = "123"
I want to emphasize though that you should test that there is actually a nested cell within the given cell range. 我想强调的是,您应该测试在给定的单元格范围内实际上是否有嵌套的单元格。 If you don't, your code could fail.
否则,您的代码可能会失败。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.