我有 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