0

我有 VB.net 代码,但我需要将其转换为 VBScript。我需要打开一个word文档来计算表格,如果有类似的Word(例如Tablein),我需要用表格替换它。但是必须在提供数据时构建表。

VB.net代码(完整代码):

dim oRow As Word.Row,oTable As Word.Table
oRow = oTable.Rows(1)
oRow.Cells(1).Range.Text = ""
If PullRow.Item("TYPE").ToString = "Traffic" Then
oRow.Cells(2).Range.Text = "T"
ElseIf PullRow.Item("TYPE").ToString = "Data" Then
oRow.Cells(2).Range.Text = "D"
End If
oRow.Cells(3).Range.Text = "C"

VBScript(直到我能写):

Dim intNoOfRows

Dim intNoOfColumns

Dim objWord

Dim objDoc

Dim objRange

Dim objTable
dim strword

intNoOfRows = 5

intNoOfColumns = 3

Set objWord = CreateObject("Word.Application")

objWord.Visible = True    

Set objDoc = objWord.Documents.open("new.docx")

g= objWord.ActiveDocument.Tables.count

Set objRange = objDoc.Range

Set objTable = objDoc.Tables(1)
objTable.Borders.Enable = True   

With objWord.Selection
  .Find.Text = "pen"
  .Find.Forward = True
  .Find.MatchWholeWord = True
  Do
    found = .Find.Execute 

    If found Then objDoc.Tables.Add objRange, 2,2
  Loop While found

End With
4

1 回答 1

0

将您创建的表分配给一个变量:

If found Then Set tbl = objDoc.Tables.Add(objRange, 2, 2)

然后使用该变量将值分配给表格单元格:

tbl.Cell(1, 1).Range.Text = "foo"
tbl.Cell(1, 2).Range.Text = 23
tbl.Cell(2, 1).Range.Text = "bar"
tbl.Cell(2, 2).Range.Text = 42
于 2013-10-21T09:03:12.907 回答