首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >读取当前选定的行

读取当前选定的行
EN

Stack Overflow用户
提问于 2015-01-16 13:57:01
回答 1查看 74关注 0票数 0

(这很可能很简单,但不知何故我找不到解决办法。)

我只想将选择的当前行读入vba中的变量。我不知道这一段。选择是在行的最开始。

我的文件是这样的。

首先,我选择表的第一行。然后我再往上挪一段。这是我想要的台词。正如你在我的第二个img中看到的,我只有第一个角色。

代码语言:javascript
复制
For Each tbl In fileInsertRange.Tables
    tbl.Rows(1).Select
    ' save caption
    Selection.Collapse
    Selection.MoveUp WdUnits.wdParagraph, 1

    tableCaption = Selection.Text

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-01-18 00:01:15

如果要将所有表标题存储在变量中,请尝试以下代码。请记住,您需要在tableCaption变量被下一个表标题覆盖之前立即使用它,或者添加一个数组来存储所有的标题。

代码语言:javascript
复制
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

如果您想通过选择表的第一行并找到表标题来继续这样做,请尝试以下代码:

代码语言:javascript
复制
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

希望这能有所帮助。祝好运。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27985569

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档