如何获得形状(VBA单词)的一系列桌子范围?
我有一张桌子的桌子。
我想在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"
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先将单元格的范围分配到变量,然后使用
setRange
方法在执行您想要的事情之前调整范围:以下将更改
cell(2,2,2, 1)
“ 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":