PDA

View Full Version : Solved: Inconsistant Run Time Error 462



akn112
10-09-2007, 11:48 AM
I've tried asking/searching everywhere but can't seem to get it figured out:banghead:

I'm getting a runtime error sometimes when i try to run the below sub. But it fails at the openworkbooks method sometimes. the error is :

"Remote Server Machine Does not Exist or is Unavailable"

I've also triple checked the file name and everything but still doesnt budge. I've been trying to debug this problem the whole day...and it's killing my brain cells :bug: Heres the code:


Sub Letter_(strTemplateFilePath As String, userCompleteFilePath As String, wordApplication As Word.Application, uaUserAccess As CUserAccess)
Dim wordDocument As Word.Document, wordDocumentAppendixA As Word.Document
Dim docDocument As Document
Dim combineFileName As String
Dim sections As String

Dim eaExcelApplication As Excel.Application
combineFileName = buildFileName(uaUserAccess, "COMBINE")

'Get the excel app
'Check for existing instance of Excel
On Error Resume Next
Set eaExcelApplication = GetObject(, "Excel.Application")
On Error GoTo 0
If eaExcelApplication Is Nothing Then
Set eaExcelApplication = CreateObject("Excel.Application")
End If

eaExcelApplication.WorkBook.Open CurrentProject.Path & IdentityMgmtFolder & "Archive\Combined\" & combineFileName, , , , "xxPass"

' On Error Resume Next
For Each docDocument In wordApplication.Documents
If docDocument.Path & "\" & docDocument.Name = userCompleteFilePath Then
wordApplication.Documents(docDocument.Name).Close SaveChanges:=True
End If
Next
'On Error Resume Next

Call FSOCopy(strTemplateFilePath, userCompleteFilePath)
Set wordDocument = wordApplication.Documents.Open(userCompleteFilePath)

With wordApplication
...

Tommy
10-09-2007, 11:58 AM
A shot in the dark
change:
If eaExcelApplication Is Nothing Then
Set eaExcelApplication = CreateObject("Excel.Application")
End If


If Err.Number <> 0 Then
Err.Clear
Set eaExcelApplication = CreateObject("Excel.Application")
End If

akn112
10-09-2007, 12:04 PM
nah, still getting the same error. This type of error seems really difficult to debug since theres no apparent pattern to it

Tommy
10-09-2007, 12:37 PM
Change

CurrentProject.Path & IdentityMgmtFolder & "Archive\Combined\"

To

CurrentProject.Path & "\" & IdentityMgmtFolder & "\" & "Archive\Combined\"

akn112
10-10-2007, 05:36 AM
hey tommy, the variable identitymgmtfolder is "\identitymgmtfolder\"

Tommy
10-10-2007, 04:20 PM
Change Workbook to Workbooks

eaExcelApplication.WorkBook.Open



eaExcelApplication.Workbooks.Open CurrentProject.Path & IdentityMgmtFolder & "Archive\Combined\" & combineFileName, , , , "xxPass"

akn112
10-11-2007, 05:28 AM
Thanks for your input Tommy! I tried changing it but same deal. I think it had something to do with having the file open prior to my code or something. Here's what i did.

This is kind of a quick fix, but i dont know what actually "fixed" it.

so my code in the big picture actually looks like this


'very simplified view
public sub cmd_click
EditXLS(parameters)
Letter_(parameters)
end sub

and editXLS actually creates the xls that Letter_ uses ( the one seen in the code). However, sometimes that xls, the one being created in EditXLS already exists, so i did the usual "Would you like to overwrite blah blah, yes".
it was after that manipulation that i got the error in Letter_

Now what ive done is this


'very simplified view
public sub cmd_click
if not fileexists(thatexcelfile) then EditXLS(parameters)
Letter_(parameters)
end sub

Seems to somewhat work now. Hopefully it'll continue to work