(这很可能很简单,但不知何故我找不到解决办法。)
我只想将选择的当前行读入vba中的变量。我不知道这一段。选择是在行的最开始。
我的文件是这样的。

首先,我选择表的第一行。然后我再往上挪一段。这是我想要的台词。正如你在我的第二个img中看到的,我只有第一个角色。
For Each tbl In fileInsertRange.Tables
tbl.Rows(1).Select
' save caption
Selection.Collapse
Selection.MoveUp WdUnits.wdParagraph, 1
tableCaption = Selection.Text

发布于 2015-01-18 00:01:15
如果要将所有表标题存储在变量中,请尝试以下代码。请记住,您需要在tableCaption变量被下一个表标题覆盖之前立即使用它,或者添加一个数组来存储所有的标题。
Sub get_table_caption()
Dim currentTable As Table
Dim tableCaption As String
'Loop through all tables on active document
For Each currentTable In ActiveDocument.Tables
'Get tables caption and store in a variable called "tableCaption"
currentTable.Select
Selection.Collapse
Selection.MoveUp WdUnits.wdParagraph, 1
Selection.Expand wdLine
tableCaption = Selection.Text
Debug.Print tableCaption
'Do stuff with the tables caption
Next
End Sub如果您想通过选择表的第一行并找到表标题来继续这样做,请尝试以下代码:
Sub get_table_caption()
Dim tableCaption As String
'Get tables caption and store in a variable called "tableCaption"
Selection.Collapse
Selection.MoveUp WdUnits.wdParagraph, 1
Selection.Expand wdLine
tableCaption = Selection.Text
Debug.Print tableCaption
End Sub希望这能有所帮助。祝好运。
https://stackoverflow.com/questions/27985569
复制相似问题