Error when opening excel file for certain user - 'The remote procedure call failed..."

0

I have a windows application written in vb.NET that pulls details from a big excel workbook and uses them to create site specific documents, depending on what site a user of the application has been assigned. The application then opens up the excel workbook it creates, and populates certain cells with the desired information, before opening a word document it has created to do similar.

The application was working perfectly for all users, but has recently stopped working for a user with Windows 8.1 and 32-bit Excel 2013. The application opens up the master excel workbook and pulls all necessary information from it, however when it tries to open the excel workbook it has created, it cannot proceed any further and eventually throws the following error:

The remote procedure call failed. (Exception from HRESULT: 0X800706BE).

The following is the code that opens up the master workbook, closes it, then copies the workbook template, renames it and finally opens it.

Imports Excel = Microsoft.Office.Interop.Excel   
Public Class Form1

    Dim excelApp As Excel.Application = Nothing
    Dim excelWB As Excel.Workbook = Nothing
    Dim excelWS As Excel.Worksheet = Nothing

    Dim fso As Scripting.FileSystemObject

    Dim MasterLogLoc As String 'Path to the master workbook is stored in this string
    Dim SiteTempLoc As String 'Path to the workbook template
    Dim SiteWbLoc As String 'Path to the newly created wb 

    excelApp = New Excel.Application                                                
    excelWB = excelApp.Workbooks.Open(Filename:=MasterLogLoc, [ReadOnly]:=True, UpdateLinks:=False)    
    excelApp.Visible = False                                                        
    excelWS = excelWB.Worksheets("Master")                                                    
    excelWS.Select() 

    'Whatever details that are needed are grabbed                                                    

    excelWB.Close(SaveChanges:=False)
    excelApp.Quit()
    excelApp = Nothing
    excelWB = Nothing

    'Next the template is copied and the newly created workbook is opened

    fso = New Scripting.FileSystemObject  
    fso.CopyFile(Source:=SiteTempLoc, Destination:=SiteWbLoc)
    fso = Nothing 

    'The application times out at the next part 

    excelApp = New Excel.Application
    excelWB = excelApp.Workbooks.Open(SiteWbLoc)                       
    excelApp.Visible = False

    'The application times out at the above part

    'Whatever needs to be done to the worksheet is completed

    excelWB.Save()
    excelWB.Close()
    excelApp.Quit()

End Class

My computer is Windows 7, with Excel 2010 64-bit, and the application still works perfectly, it also still works perfectly on another Windows 7 computer.

The first time the user got this error, I got them to manually open up the workbook template, which showed that they did not have the file as a trusted document for their PC. After fixing this, they ran the application successfully but the next day the error appeared again, even though the workbook was now a trusted document.

The fact that the application opens up an already existing workbook successfully, but cannot open the workbook created on that PC, appears to be the main sign of the problem, however I am unsure where to proceed to next for troubleshooting this.

Could late-binding work? Or have I something missing from my code that makes the application more robust when operating on different versions of windows and excel?

excel
vb.net
asked on Stack Overflow Mar 26, 2018 by Jay

1 Answer

0

I tried a late binding solution, however that didn't solve the problem, but I did manage to find a solution.

The excel worksheet the application copied had links to other excel worksheets - the links were outdated and not functioning correctly, which meant that every time the newly created worksheet was opened, a user had to select 'Enable Content' - not sure how I missed this!

I solved this problem by:

1) Fixing the links on the worksheet template being copied

2) Making the network drives, which held both the worksheet template and also the worksheets that the template had links to, trusted locations.

answered on Stack Overflow Mar 28, 2018 by Jay

User contributions licensed under CC BY-SA 3.0