How to make this VBS script keep the document closed?

限于喜欢 提交于 2019-12-13 03:41:02

问题


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

回答1:


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.



来源:https://stackoverflow.com/questions/5057998/how-to-make-this-vbs-script-keep-the-document-closed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!