vba 宏:我的光标在哪个表中? [英] vba macro: Which table my cursor is in?

查看:54
本文介绍了vba 宏:我的光标在哪个表中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

写一个宏我发现我需要跳过表格内容并将光标放在后面,为此我使用了一个代码

Writing a macro I found out that I need to skip the table contents and place my cursor right after that, for this I am using a code as

     Selection.Tables(cnt).Select
     Selection.Collapse WdCollapseDirection.wdCollapseEnd

这里,cnt 是一个计数器值,每次找到表时都会增加,但是如果在选择性页面中运行宏,那么我怎么知道我的光标所在的第 n 个表的数量.

Here, cnt is a counter value which increases each time a table is found, but if run the macro in selective pages then how will i know the number of nth table inside which my cursor is.

推荐答案

重要!此解决方案允许您查找文档中当前选定表格的数量.

将此功能添加到您的任何模块:

Add this function to any your Module:

Function WhichTableNo(RNG As Range)

If RNG.Tables.Count > 0 Then
    Dim DOC As Document
    Set DOC = RNG.Parent

    Dim rngTMP As Range
    Set rngTMP = DOC.Range(0, RNG.Tables(1).Range.End)

    WhichTableNo = rngTMP.Tables.Count
Else
    WhichTableNo = "Not in the table"
End If
End Function

并检查表号,您可以这样调用:

and to check the table number you could call it this way:

debug.Print WhichTableNo(Selection.Range)

因此,您将获得当前所在的桌子数量.

As a result you get number of table you are currently in.

这篇关于vba 宏:我的光标在哪个表中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆