Vb.net 无法访问此文件的原因和解决方案是什么?

Vb.net 无法访问此文件的原因和解决方案是什么?,vb.net,excel,comexception,interopservices,Vb.net,Excel,Comexception,Interopservices,试图让一个基本的VB.NET Excel文件创建应用程序正常工作,从中的一些示例代码开始,我得到以下代码的错误msgs: Private Sub ButtonCreateExcelFile_Click( sender As Object, e As EventArgs) Handles ButtonCreateExcelFile.Click Dim xlApp As New Excel.Application Dim xlWorkBook As Excel.Workbook

试图让一个基本的VB.NET Excel文件创建应用程序正常工作,从中的一些示例代码开始,我得到以下代码的错误msgs:

Private Sub ButtonCreateExcelFile_Click( sender As Object,  e As EventArgs) Handles ButtonCreateExcelFile.Click
    Dim xlApp As New Excel.Application
    Dim xlWorkBook As Excel.Workbook
    Dim xlWorkSheet As Excel.Worksheet
    Dim misValue As Object = System.Reflection.Missing.Value

    xlWorkBook = xlApp.Workbooks.Add(misValue)
    xlWorkBook.Application.Visible = True
    xlWorkBook.Application.ScreenUpdating = False
    xlWorkSheet = xlWorkBook.Sheets("sheet1")
    'xlWorkSheet.SaveAs("C:\vbexcel.xlsx")
    xlWorkSheet.SaveAs("C:\\misc\\vbexcel.xls")
    . . .
我首先试过这个:

xlWorkSheet.SaveAs("C:\vbexcel.xlsx")
(未能逃脱反攻),而这个(“vbexcel.xlsx”)不知何故被误认为是“52587100”,正如您在这里看到的:

System.Runtime.InteropServices.COMException was unhandled
  ErrorCode=-2146827284
  HelpLink=C:\Program Files (x86)\Microsoft Office\Office12\1033\XLMAIN11.CHM
  HResult=-2146827284
  Message=Microsoft Office Excel cannot access the file 'C:\52587100'. There are several possible reasons:

• The file name or path does not exist.
• The file is being used by another program.
• The workbook you are trying to save has the same name as a currently open workbook.
  Source=Microsoft Office Excel. . .
通过向路径添加子文件夹和转义字符,如下所示:

xlWorkSheet.SaveAs("C:\\misc\\vbexcel.xlsx")
…我得到了一个类似的错误,但这次它只是说它无法访问该文件(没有声明文件名为“52587100”):


这段代码有什么问题,导致无法访问该文件?

一些可能的解决方案:C的根目录现在甚至连管理员(也称超级用户)都无法访问。您需要提升权限才能访问它。
System.Runtime.InteropServices.COMException was unhandled
  ErrorCode=-2146827284
  HelpLink=C:\Program Files (x86)\Microsoft Office\Office12\1033\XLMAIN11.CHM
  HResult=-2146827284
  Message=The file could not be accessed. Try one of the following: