Word 自动化:不可编辑
我正在使用 Access 将数据发送到我在 Word 中创建的模板。成功发送数据后,我需要使打开的 Word 文档不可编辑。
另外,我注意到在完成文档后它会提示保存。是否可以删除此提示,但允许保存功能。
这是我用来执行 Word 自动化的代码:
' Create a Word document from template.
Dim WordApp As Word.Application
Dim strTemplateLocation As String
Dim myVariable As String
myVariable = “TEST!!”
' Specify location of template
strTemplateLocation = Left(CurrentDb.Name, InStrRev(CurrentDb.Name, "\")) & "test.dot"
Set WordApp = CreateObject("Word.Application")
WordApp.Visible = True
WordApp.WindowState = wdWindowStateMaximize
WordApp.Documents.Add Template:=strTemplateLocation, NewTemplate:=False
' Replace each bookmark with field contents.
WordApp.Selection.GoTo what:=wdGoToBookmark, Name:="myBookmark"
WordApp.Selection.TypeText myVariable
DoEvents
WordApp.Activate
Set WordApp = Nothing
I am using Access to send data to a template I created in Word. After it succesfully sends the data I need to make the open Word Document NON-editable.
Also, I notice that after I am done with the Document it prompts to save. Is it possible to remove this prompt, BUT allow the capability to save.
This is the code I am using to do the Word Automation:
' Create a Word document from template.
Dim WordApp As Word.Application
Dim strTemplateLocation As String
Dim myVariable As String
myVariable = “TEST!!”
' Specify location of template
strTemplateLocation = Left(CurrentDb.Name, InStrRev(CurrentDb.Name, "\")) & "test.dot"
Set WordApp = CreateObject("Word.Application")
WordApp.Visible = True
WordApp.WindowState = wdWindowStateMaximize
WordApp.Documents.Add Template:=strTemplateLocation, NewTemplate:=False
' Replace each bookmark with field contents.
WordApp.Selection.GoTo what:=wdGoToBookmark, Name:="myBookmark"
WordApp.Selection.TypeText myVariable
DoEvents
WordApp.Activate
Set WordApp = Nothing
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Document
对象有一个Saved
属性,如果进行任何更改,该属性通常会更改为False
。如果您将此属性设置为True
,则关闭文档时不会提示您保存文档,但您仍然可以手动保存它(通过Save
或另存为...
)如果你愿意的话。您可以使用
Document
对象的Protect
方法来限制用户可以进行的更改。例如,您可以使用参数 wdAllowOnlyReading 来调用它,这意味着不能进行任何类型的更改。您可能还需要查看保护文档的密码,以防止用户再次简单地取消保护它The
Document
object has aSaved
property which normally changes toFalse
if any changes are made. If you set this property toTrue
then you won't be prompted to save the document when you close it but you can still save it manually (viaSave
orSave As...
) if you want to.You can use the
Protect
method of theDocument
object to restrict the changes which the user can make. For example, you can call it with the parameterwdAllowOnlyReading
which will mean that no changes of any kind can be made. You may also need to look at password protecting the document to prevent the user from simply unprotecting it again这应该可以满足您的需要。从 Excel 测试,而不是 Access,因此您需要修复模板路径
This should do what you need. Tested from Excel, not Access, so you'll need to fix the template path