[英]How can get a Range of Cell of Table in a Shape (VBA Word)?
我有一張桌子放在字形中。
我想在 Text ="123" 處獲得 Cell(2,1) 中的范圍
我嘗試了這段代碼,但它無法獲得形狀中的表格單元格范圍:
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"
筆記:
如果表格放入文檔中,我的代碼將起作用。 但是當桌子放入形狀時不起作用
如何獲得形狀中的表格單元格范圍?
首先將單元格的范圍分配給變量,然后使用SetRange
方法調整范圍,然后再執行您想要的操作:
下面將Cell(2,1)
第 1 段中前 3 個字符的文本更改為“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"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.