VBS:在MSWord表中附加两行。怎么做?

时间:2011-11-27 05:08:49

标签: vbscript ms-word line

Here我了解了一个VBS脚本,该脚本会在MS Word表格中附加一行。要添加的行包含四个单元格,每个单元格包含一个单词:

  

龟,猎豹,公鸡,枫木

脚本运行正常。它是这样的:

Set wd = CreateObject("Word.Application")    
wd.Visible = True    
Set doc = wd.Documents.Open ("E:\my_folder\add_to_this_table.doc")    
Set r = doc.Tables(1).Rows.Add    
aa = Split("turtle,cheetah,rooster,maple", ",")    
For i = 0 To r.Cells.Count - 1    
  r.Cells(i + 1).Range.Text = aa(i)    
Next

现在,如果我需要在此表中添加两行,该怎么办?

第二行是:

  

鬣蜥,熊,鹰,桤木

我试过这种方式,但它不起作用:

Set wd = CreateObject("Word.Application")    
wd.Visible = True    
Set doc = wd.Documents.Open ("E:\my_folder\add_to_this_table.doc")    
Set r = doc.Tables(1).Rows.Add    
aa = Split("turtle,cheetah,rooster,maple", ",")    
For i = 0 To r.Cells.Count - 1    
  r.Cells(i + 1).Range.Text = aa(i)    
Set r = doc.Tables(1).Rows.Add    
bb = Split("iguana,bear,hawk,alder", ",")    
For i = 0 To r.Cells.Count - 1    
  r.Cells(i + 1).Range.Text = bb(i)    
Next

我在这里做错了什么?

1 个答案:

答案 0 :(得分:1)

你忘记了第一个For循环的Next。