VBA 中的错误 462:找不到远程服务器机器 [英] Error 462 in VBA : remote server machine not found

查看:39
本文介绍了VBA 中的错误 462:找不到远程服务器机器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面的代码是在vba中读取一个word文件.但它显示错误

following code is to read a word file in vba. But its showing an error

VBA 中的错误 462:找不到远程服务器机器.

Sub abc()
    Dim fileReader As String
    Dim wrdApp As Word.Application
    Dim wrdDoc As Word.Document
    Dim singleLine As Paragraph
    Set wrdApp = CreateObject("Word.Application")
    Set wrdDoc = wrdApp.Documents.Open("C:Documents and SettingsAdministratorMy DocumentsDownloadsfwfileswebs.doc")
    With wrdDoc
        Dim p As Paragraph
        For Each p In wrdDoc.Paragraphs
            fileReader = p.Range.Text
        Next p
    End With
End Sub

提前致谢

推荐答案

启动两次会不会坏掉?

原因

Visual Basic 已经建立了对 Excel 的引用,因为有一行代码调用了 Excel 对象、方法或属性,而没有使用 Excel 对象变量限定元素.在您结束程序之前,Visual Basic 不会释放此引用.当代码运行多次时,此错误引用会干扰自动化代码.

Visual Basic has established a reference to Excel because of a line of code that calls an Excel object, method, or property without qualifying the element with an Excel object variable. Visual Basic does not release this reference until you end the program. This errant reference interferes with automation code when the code is run more than one time.

分辨率

要解决此问题,请修改代码,以便使用适当的对象变量限定对 Excel 对象、方法或属性的每次调用.

To resolve this problem, modify the code so each call to an Excel object, method, or property is qualified with the appropriate object variable.

来源

看看这里:http://support.microsoft.com/default.aspx?kbid=178510

你也可以看看这里:http://www.tek-tips.com/viewthread.cfm?qid=756598

帖子的作者收到错误,因为他没有使用 Access 对象来打开和关闭数据库.

The author of the post was getting the error because he was not using the Access object to open and close the database.

最后:

  • 你应该避免在 Word 应用程序对象中使用 with 块
  • 你应该释放你的变量(Set ... As Nothing, wrdApp.Close, ...)

这篇关于VBA 中的错误 462:找不到远程服务器机器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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