Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
896 views
in Technique[技术] by (71.8m points)

ms word - Error 462 in VBA : remote server machine not found

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

Error 462 in VBA : remote server machine not found.

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

Thanks in advance

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Does it break when you launch it twice ?

Cause

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.

Resolution

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

Source

Have a look here : http://support.microsoft.com/default.aspx?kbid=178510


You could also have a look here : http://www.tek-tips.com/viewthread.cfm?qid=756598

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


And finally :

  • you should avoid using the with block with a Word Application object
  • you should free your variables (Set ... As Nothing, wrdApp.Close, ...)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...