如何获得形状(VBA单词)的一系列桌子范围?

发布于 2025-02-08 19:38:31 字数 812 浏览 2 评论 0原文

我有一张桌子的桌子。

我想在text =“ 123”

“在此处输入图像说明”

我尝试此代码,但是它无法获得形状的单元格范围:

Dim oApp As Object
Dim oShape As Object
Dim oTable As Object
Dim oDoc As Object

Set oApp = CreateObject("Word.Application")
oApp.Visible = True

Set oDocument = oApp.Documents.Open("E:\2022\t1.docx")
Set oShape = oDocument.Shapes(1)
Set oTable = oShape.TextFrame.TextRange.Tables(1)

Dim iStart As Integer
Dim iEnd As Integer
iStart = oTable.Cell(2, 1).Range.Paragraphs(1).Range.Start
iEnd = iStart + 3
oDocument.Range(iStart, iEnd).Text = "ABC"

注意:我的代码:

我的代码如果桌子放入文档,将有效。但是,当桌子放置一个形状时,

如何获得形状的一系列桌子范围?

I have a table put in a Shape of Word.

I want get a Range in Cell(2,1) at Text ="123"

enter image description here

I try this code , but it can't get a Range of Cell of Table in Shape:

Dim oApp As Object
Dim oShape As Object
Dim oTable As Object
Dim oDoc As Object

Set oApp = CreateObject("Word.Application")
oApp.Visible = True

Set oDocument = oApp.Documents.Open("E:\2022\t1.docx")
Set oShape = oDocument.Shapes(1)
Set oTable = oShape.TextFrame.TextRange.Tables(1)

Dim iStart As Integer
Dim iEnd As Integer
iStart = oTable.Cell(2, 1).Range.Paragraphs(1).Range.Start
iEnd = iStart + 3
oDocument.Range(iStart, iEnd).Text = "ABC"

Notes:

My code will working, if table put in document. But not working when table put in a Shape

How can get a Range of Cell of Table in a Shape?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

清醇 2025-02-15 19:38:32

首先将单元格的范围分配到变量,然后使用setRange方法在执行您想要的事情之前调整范围:

以下将更改cell(2,2,2, 1)“ ABC”的第一段:

Dim rng As Range
Set rng = oTable.Cell(2, 1).Range.Paragraphs(1).Range

rng.SetRange rng.Start, rng.Start + 3
rng.Text = "ABC"

Assign the range of the cell to a variable first then use SetRange method to adjust the range before doing what you want:

Below will change the text of the first 3 characters in the Cell(2,1) 1st paragraph to "ABC":

Dim rng As Range
Set rng = oTable.Cell(2, 1).Range.Paragraphs(1).Range

rng.SetRange rng.Start, rng.Start + 3
rng.Text = "ABC"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文