A
al
Greetings,
I used article Q317109
(http://support.microsoft.com/default.aspx?scid=kb;EN-US;Q317109) to
solve the problem of Excel prcocess does not stop after close. The
problem I faced with the solution provided is that between the export
of data to Excel and destryoing of Excel's objects (calling NAR sub),
I need to provide a prompt to the user to save file to a location, as
per user's choice. However, If the user elects CANCEL option (in case
the file already existt), this will still leave the process runing and
gives a message "exception from HResult:0x800A03EC"?????
Any Idea why is that or any alternative solution will be greatly
apprciated!!
'This is the code I used to export to Excel. Please Add DG to fill
with data.
Private Sub btnexport_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles btnexport.Click
Dim ex As Excel.Application
ex = New Excel.Application
Dim bs As Excel.Workbooks = ex.Workbooks
Dim b As Excel.Workbook = bs.Add
Dim s As Excel.Worksheet = ex.ActiveSheet
ex.Visible = True
s.Visible = Excel.XlSheetVisibility.xlSheetVisible
Try
'Nex, I will export what is in the dataset to Excel. I did one item
for tesing
s.Range("A1").Value = DataSet11.Tables(0).Rows(1).Item(2)
'Here I need to prompt the user for saving or use Next code for
implicit saving.
ex.SaveWorkspace() 'if file already exists and user elect to
cancel, then, a proplem(described at the begning)
Catch err As Exception
MsgBox(err.Message)
Finally
nar(s)
b.Close(False)
nar(b)
nar(bs)
ex.Quit()
nar(ex)
GC.Collect()
End Try
End Sub
Sub nar(ByVal o)
Try
System.Runtime.InteropServices.Marshal.ReleaseComObject(o)
Catch
Finally
o = Nothing
End Try
End Sub
MTIA,
Grawsha
I used article Q317109
(http://support.microsoft.com/default.aspx?scid=kb;EN-US;Q317109) to
solve the problem of Excel prcocess does not stop after close. The
problem I faced with the solution provided is that between the export
of data to Excel and destryoing of Excel's objects (calling NAR sub),
I need to provide a prompt to the user to save file to a location, as
per user's choice. However, If the user elects CANCEL option (in case
the file already existt), this will still leave the process runing and
gives a message "exception from HResult:0x800A03EC"?????
Any Idea why is that or any alternative solution will be greatly
apprciated!!
'This is the code I used to export to Excel. Please Add DG to fill
with data.
Private Sub btnexport_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles btnexport.Click
Dim ex As Excel.Application
ex = New Excel.Application
Dim bs As Excel.Workbooks = ex.Workbooks
Dim b As Excel.Workbook = bs.Add
Dim s As Excel.Worksheet = ex.ActiveSheet
ex.Visible = True
s.Visible = Excel.XlSheetVisibility.xlSheetVisible
Try
'Nex, I will export what is in the dataset to Excel. I did one item
for tesing
s.Range("A1").Value = DataSet11.Tables(0).Rows(1).Item(2)
'Here I need to prompt the user for saving or use Next code for
implicit saving.
ex.SaveWorkspace() 'if file already exists and user elect to
cancel, then, a proplem(described at the begning)
Catch err As Exception
MsgBox(err.Message)
Finally
nar(s)
b.Close(False)
nar(b)
nar(bs)
ex.Quit()
nar(ex)
GC.Collect()
End Try
End Sub
Sub nar(ByVal o)
Try
System.Runtime.InteropServices.Marshal.ReleaseComObject(o)
Catch
Finally
o = Nothing
End Try
End Sub
MTIA,
Grawsha