问题描述
所以我有一个MS Access应用程序打开单词并打开文件模板,根据数据库值进行一些更改,关闭并保存Word文档。 一切都很好。 除了...
So I have a MS Access application that opens word and opens a file template, makes some changes based on DB values, closes and saves the Word document. All is well. Except...
有时候,当我尝试打开文件时,我会得到这个: "Microsoft Visual Basic运行时错误"462':远程服务器计算机不存在5或不可用。"
Sometimes I get this when I attempt to open the file: "Microsoft Visual Basic Run-Time error '462': The remote server machines does not exist5 or is unavailable."
运行任务管理器已显示存在此错误时"后台进程"显示为"Word"。 我可以杀死这个过程,VBA按预期工作。 Word不应该运行...我已经退出它通常
等,但显然它的一部分仍然作为一个bg进程运行。 有时等待一段时间(15分钟左右),bg过程将自行消失。
Running task manager has shown that this error occurs when there is a "background process" shown that is "Word". I can kill that process, and the VBA works as expected. Word should not be running...I have exited it normally etc, but apparently some piece of it is still running as a bg process. Sometimes waiting a while (15 minutes or so) and the bg process will disappear on its own.
相关代码片段:
Dim objWord As Word.Application
Dim Doc As Word.Document
设置objWord = CreateObject(" Word.Application"))
...
设置Doc = objWord.Documents.Open(FileName_Str)
Dim objWord As Word.Application
Dim Doc As Word.Document
Set objWord = CreateObject("Word.Application")
...
Set Doc = objWord.Documents.Open(FileName_Str)
问题:如何捕获此错误或阻止它发生?
QUESTION: How can I trap this error, or prevent it from occurring?
推荐答案
在我们尝试"陷阱"之前问题是,让我们试着"避免"它首先。你的代码中有这样的东西吗?
Before we try to "trap" the problem, let's try to "avoid" it first. Do you have something like this one in your code?
设置objWord = Nothing
Set objWord = Nothing
上面的行应该"释放"该过程并从后台进程列表中删除Word。
The above line should "release" the process and remove Word from the list of background processes.
只需2美分......
Just my 2 cents...
这篇关于使用MS Word在Access中集成VBA的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!