开发者

How to make this VBS script keep the document closed?

开发者 https://www.devze.com 2023-02-12 18:47 出处:网络
I just received this VBS code that appends a line to my table in MS \"Word\" 2003. It works fine, but I want it to add a line to the table without opening the file. Is it possible 开发者_如何学运维? O

I just received this VBS code that appends a line to my table in MS "Word" 2003. It works fine, but I want it to add a line to the table without opening the file. Is it possible 开发者_如何学运维? Or, perhaps, I need to use some command that would close the document as soon as it is opened.

Set wd = CreateObject("Word.Application")

wd.Visible = True

Set doc = wd.Documents.Open ("c:\docs\addtotable.doc")

Set r = doc.Tables(1).Rows.Add

aa = Split("turtle,dog,rooster,maple", ",")

For i = 0 To r.Cells.Count - 1
  r.Cells(i + 1).Range.Text = aa(i)
Next


If you don't want to open Word's window, use "wd.Visible = False" instead of "wd.Visible = True". In that case you may want to save to changed document to the same/a new file. Read the VBA documentation about .Save and .SaveAs. Closing the application by .Quit may be a good idea too.

0

精彩评论

暂无评论...
验证码 换一张
取 消