Cannot open Excel file from VB.NET - error 0x800AC472 - user permission problem

Answered Cannot open Excel file from VB.NET - error 0x800AC472 - user permission problem

  • Tuesday, April 10, 2012 11:54 PM
     
      Has Code

    Hi All,

    This is a simple fragment of my code:

    Dim exc As New Excel.Application
    Dim sht As Excel.Worksheet 
    Dim wkb As Excel.Workbook
    wkb = exc.Workbooks.Open(strFilePath)

    The last line throws an exception "Cannot open file" with certain end-user profiles. It works perfectly fine when executing from an Admin account. I just cannot figure out what user privileges and access settings may cause the error.

    Note that it also works with some end-user accounts (not admins).

    What missing user rights can cause this?

    Win XP, Excel 2007 and Excel 2010.

    Thanks!


    • Edited by astro928 Wednesday, April 11, 2012 2:45 AM
    •  

All Replies

  • Wednesday, April 11, 2012 1:01 AM
     
     
    Can the same user open the workbook from Excel itself?

    Armin

  • Wednesday, April 11, 2012 1:24 AM
     
     
    yes, it can be opened from Excel itself.
  • Wednesday, April 11, 2012 2:39 AM
     
      Has Code
    Some more information. This is the main code:


            	    Try
                                'populating a listbox - sheets
                                Dim exc As New Excel.Application
                                Dim sht As Excel.Worksheet
                                Dim wkb As Excel.Workbook
                                wkb = exc.Workbooks.Open(strFilePath)
                                Me.ListBoxImpFac.Items.Clear()
                                For Each sht In wkb.Sheets
                                    Me.ListBoxImpFac.Items.Add(sht.Name)
                                Next
    
                                wkb.Close()
                                exc.Quit()
                                releaseObject(exc)
                                releaseObject(wkb)
                                releaseObject(sht)
    
                Catch ex As Exception
                    MessageBox.Show(Me, Err.Description, "File opening error", MessageBoxButtons.OK, MessageBoxIcon.Error)
                End Try



    It throws an error  0x800AC472. Since the listbox is not populated, i assume it throws an exception on the line:

     wkb = exc.Workbooks.Open(strFilePath)
    • Edited by astro928 Wednesday, April 11, 2012 2:40 AM
    •  
  • Wednesday, April 11, 2012 10:24 AM
     
     Answered

    To see the line of error, output ex.StackTrace. What does ex.message say?

    In these cases (COM error 8xxxxxxx), take the low word (0xC472), convert to decimal (50,290) and look for the error code. One hit I found says: " Error writing to Worksheet while using an ActiveX Control". Don't know if this an error message or an explanation, anyway it tells you the possible cause. Verify if it applies.


    Armin

  • Wednesday, April 11, 2012 1:19 PM
     
     
    Where is the file located? Network path? Somewhere other than a Documents folder?

    Paul ~~~~ Microsoft MVP (Visual Basic)

  • Friday, May 11, 2012 2:29 AM
     
      Has Code

    I am back after running multiple tests on different end-user PCs. Still cannot resolve the issue. A few more points:

    1. The file may is always located on a local drive, either in a Document folder or on a C:\ drive in a directory with full access rights for that particular user.

    2. It doesn't matter what the Excel file is - it could be a complex xlsm workbook, or a simple xls with a few sheets. The point is that it cannot open the file using

    Dim exc As New Excel.Application
    Dim sht As Excel.Worksheet 
    Dim wkb As Excel.Workbook
    wkb = exc.Workbooks.Open(strFilePath)

    3. if I run the same exe code as an admin, i.e. with the option "Run as...", it works perfectly fine.

    Any more suggestions?

     

  • Thursday, August 02, 2012 7:36 PM
     
     
    astro928, did you find the solution to this, I am having the same issue and could not figure out what the cause is...