使用VBA永久重命名字表 [英] Permanently renaming word tables with VBA

查看:69
本文介绍了使用VBA永久重命名字表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用VBA表单和选项框自动将行和文本添加到word文档中的各个表。我有的代码可以重命名表和插入,但是,我需要知道表的订单号。此订单可能会随着
文档的编辑而更改。我遇到的问题是找到一种永久重命名表的方法,以便我可以找到正确的表来插入行和文本。在文档中我要在整个文档中添加多个表格,我需要确保选择正确的
一个。 

解决方案

Hi Deadly48 ,


没有属性可以直接识别文档中的表格,


作为一种解决方法,您可以将表格加入书签并通过这是一个例子。

 Sub SetBookMark()

Dim tbl As Table

For i = 1 To ActiveDocument.Tables.Count

Set tbl = ActiveDocument.Tables(i)

ActiveDocument.Bookmarks.Add" TableBK" &安培; i,tbl.Range

下一个i

结束子

Sub SelectTable()

ActiveDocument.Bookmarks(" ; TableBK1")。Range.Tables(1).Select

End Sub

最好的问候,


特里


I have a requirement to automatically add rows and text to various tables in a word document, using a VBA form and option boxes. The code I have can rename a table and insert, however, I need to know the table order number. This order may change as the document is edited. The problem I have is finding a way of permanently rename a table so that I can find the correct table to insert the row and text. In the document I'm adding multiple tables throughout the document I need to ensure I select the correct one. 

解决方案

Hi Deadly48,

There is no property could identify table in document directly,

As a workaround, you could bookmark the table and the get the table via the bookmark.

Here is the example.

Sub SetBookMark()

Dim tbl As Table

For i = 1 To ActiveDocument.Tables.Count

Set tbl = ActiveDocument.Tables(i)

ActiveDocument.Bookmarks.Add "TableBK" & i, tbl.Range

Next i

End Sub

Sub SelectTable()

ActiveDocument.Bookmarks("TableBK1").Range.Tables(1).Select

End Sub

Best Regards,

Terry


这篇关于使用VBA永久重命名字表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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