none
EXCEPTION ERROR 0X800A03EC ON SAVE.AS COMMAND RRS feed

  • Question

  • i am facing a problem on save as command. i m currently working on a project in which i take the data from the the database and row by row i print it on the excel file . but on saving it generates the error code 0x800a03ec .. dont know why .. the similar code works fine for the another form doing the same work but generates problm on one form ..

    can anyone plz help 

    providing the line which leads to error

                        xl.SaveAs(Application.StartupPath & "\Bill\" + branch + "\Export\" + a + ".xlsx")


    here xl is the name for worksheet and a is the variable for the bill number

    kindly help... thanks 

    Sunday, January 25, 2015 3:26 PM

All replies

  • i am facing a problem on save as command. i m currently working on a project in which i take the data from the the database and row by row i print it on the excel file . but on saving it generates the error code 0x800a03ec

    You should not use "+" for string concatenation: use "&" throughout.

    There are many reasons that Excel will throw this error, and they are mostly to do with data that is invalid for some reason, so it is not the sort of thing that can be diagnosed remotely.   You should ask in an Excel forum for a list of possible causes, and then examine your spreadsheet in detail to see which ones might apply in this case.

    https://social.msdn.microsoft.com/Forums/office/en-US/home?forum=exceldev

    Sunday, January 25, 2015 9:13 PM
  • Hello,

    There are many ways for this to happen and in short this is done either by a) the file is in use already b) poorly/incorrect method of access one or more objects to a wrong method call on an object.

    The example below is to show one of many ways to properly write data to a WorkSheet and save.

    Special note: Many may look at this code and say "It can be done with less lines of code" which is true but 99 percent of the time less code equals code that will not release all objects on a customer's machine until the manually release via Task Manager or reboot their machine.

    Option Strict On
    Option Infer On
    
    Imports Excel = Microsoft.Office.Interop.Excel
    Imports Microsoft.Office
    Imports System.Runtime.InteropServices
    
    Module OpenWorkSheets
        Public Sub DemoDict()
            Dim DictCellData As New Dictionary(Of String, String) _
                From
                    {
                        {"A1", "Month"},
                        {"A2", "January"},
                        {"A3", "February"},
                        {"A4", "March"},
                        {"A5", "April"},
                        {"B1", "Money Spent"},
                        {"B2", "1000.00"},
                        {"B3", "1500.00"},
                        {"B4", "1200.00"},
                        {"B5", "1100.00"}
                    }
    
            OpenExcelWriteData(IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "WS3.xlsx"), "Sheet1", DictCellData)
    
        End Sub
        Public Sub OpenExcelWriteData(ByVal FileName As String, ByVal SheetName As String, ByVal DictCellData As Dictionary(Of String, String))
            Dim Proceed As Boolean = False
    
            Dim xlApp As Excel.Application = Nothing
            Dim xlWorkBooks As Excel.Workbooks = Nothing
            Dim xlWorkBook As Excel.Workbook = Nothing
            Dim xlWorkSheet As Excel.Worksheet = Nothing
            Dim xlWorkSheets As Excel.Sheets = Nothing
            Dim xlRange1 As Excel.Range = Nothing
            Dim xlInterior As Excel.Interior = Nothing
            Dim xlColumns As Excel.Range = Nothing
    
            xlApp = New Excel.Application
            xlApp.DisplayAlerts = False
            xlWorkBooks = xlApp.Workbooks
            xlWorkBook = xlWorkBooks.Open(FileName)
    
            xlApp.Visible = False
    
            xlWorkSheets = xlWorkBook.Sheets
    
            For x As Integer = 1 To xlWorkSheets.Count
                xlWorkSheet = CType(xlWorkSheets(x), Excel.Worksheet)
    
                If xlWorkSheet.Name = SheetName Then
                    Proceed = True
                    Exit For
                End If
    
                Runtime.InteropServices.Marshal.FinalReleaseComObject(xlWorkSheet)
                xlWorkSheet = Nothing
    
            Next
    
            If Proceed Then
                For Each Item In DictCellData
                    xlRange1 = xlWorkSheet.Range(Item.Key)
                    xlRange1.Value = Item.Value
                    Marshal.FinalReleaseComObject(xlRange1)
                    xlRange1 = Nothing
                Next
                xlWorkSheet.SaveAs(FileName)
            Else
                MessageBox.Show(SheetName & " not located.")
            End If
    
            xlWorkBook.Close()
            xlApp.UserControl = True
            xlApp.Quit()
    
            ReleaseComObject(xlInterior)
            ReleaseComObject(xlRange1)
            ReleaseComObject(xlWorkSheets)
            ReleaseComObject(xlWorkSheet)
            ReleaseComObject(xlWorkBook)
            ReleaseComObject(xlWorkBooks)
            ReleaseComObject(xlApp)
        End Sub
        Private Sub ReleaseComObject(ByVal obj As Object)
            Try
                If obj IsNot Nothing Then
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(obj)
                    obj = Nothing
                End If
            Catch ex As Exception
                obj = Nothing
            End Try
        End Sub
    End Module
    

    I have a ton of examples where a dozen or so will be found by clicking here that will check one item but there are many more in the same folder.

    For creating a path and filename, here is a method that I would use. Note AppDomain.CurrentDomain.BaseDirectory is used and the reason, if you ever place Application.StartuPath into a class project code module or class it is not available but the other is.

    Dim Branch As String = "FolderName"
    Dim a As String = "SomeFile.xlsx"
    Dim MyFileName As String = IO.Path.Combine(
        AppDomain.CurrentDomain.BaseDirectory, "Bill", Branch, "Export", a)


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem.

    Monday, January 26, 2015 10:28 AM
  • thanks Acamar for sharing  your knowledge .. but changing concatenation symbol doesnt help out it again shows the same error ... 

    if any other way out to solve this problem .. u r most welcome ..

    thanks 

    Monday, January 26, 2015 10:58 AM
  • It seems you try to save the data in a Program Files folder.

    With the newer operating systems that is write protected.


    Success
    Cor

    Monday, January 26, 2015 11:15 AM
  • hello kevininstructor

    thanks for sharing your knowledge ... but by changing the application.startup path to other doesnt help out...

    it shows the same error again .. any more way to solve this error is most welcome 

    thanks 

    Monday, January 26, 2015 11:18 AM
  • thanks Acamar for sharing  your knowledge .. but changing concatenation symbol doesnt help out it again shows the same error ...

    Changing the concatenation character will not help with the error, but it is important for correct operation of your program.

    To deal with the error you need to enquire in an Excel forum for the possible causes of this error and determine which ones are likely in your case and investigate them one by one. See here: https://social.msdn.microsoft.com/Forums/office/en-US/home?forum=exceldev

    • Edited by Acamar Monday, January 26, 2015 11:40 AM sp
    Monday, January 26, 2015 11:32 AM
  • hello kevininstructor

    thanks for sharing your knowledge ... but by changing the application.startup path to other doesnt help out...

    it shows the same error again .. any more way to solve this error is most welcome 

    thanks 


    If you note in my reply that I addressed the path aspect secondly to the code used to actually work with Excel. Assuming the project is in a location (and the path exisits) that you have rights to then the path issue goes away and we are left with code issues excluding the path aspect. With that said why not show the code?

    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem.

    Monday, January 26, 2015 1:34 PM
  • Assuming the project is in a location (and the path exisits) that you have rights to then the path issue goes away and we are left with code issues excluding the path aspect. With that said why not show the code?

    Data and formatting issues will also produce the error, so OP really needs to supply the code, the SS being worked on and some sample data.

    Monday, January 26, 2015 8:36 PM