我有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
答案 0 :(得分: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