如何使该VBS脚本保持文档关闭? [英] How to make this VBS script keep the document closed?

查看:150
本文介绍了如何使该VBS脚本保持文档关闭?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚收到了此VBS代码,该代码在MS"Word" 2003中向我的表添加了一行.它工作正常,但是我希望它在不打开文件的情况下向表中添加一行.是否有可能 ?或者,也许我需要使用一些命令来在打开文档后立即将其关闭.

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

推荐答案

如果您不想打开Word的窗口,请使用"wd.Visible = False"代替"wd.Visible = True".在这种情况下,您可能需要将更改后的文档保存到相同/新文件中.阅读有关.Save和.SaveAs的VBA文档.通过.Quit关闭应用程序也是一个好主意.

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.

这篇关于如何使该VBS脚本保持文档关闭?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆