All pastes #556916 Raw Edit

Steakk

public text v1 · immutable
·published 2007-06-10 20:11 UTC
rendered paste body
    Private Sub WriteToExcel(ByVal filename As String)
        'If file already exists, remove it  
        'If File.Exists(xlsSaveFile) Then File.Delete(xlsSaveFile)
        Try
            theWorkbook = oWorkbooks.Open("C:\cbcs.xls")
            oSheet = MyExcel.ActiveSheet
            oSheet.Name = "Inventory List"
            oSheet.Range("B4").Value = "Cabling"
            oSheet.Range("C4").Value = "100"
            oSheet.Range("D4").Value = "0.26"
            theWorkbook.SaveAs("C:\cbcs2.xls")
            theWorkbook.Close()
            MyExcel.Quit()
            GC.Collect()
            GC.WaitForPendingFinalizers()
        Catch ex As Exception
            Throw New Exception("Error creating Excel spreadsheet:" & ex.Message.ToString())
        Finally
            oSheet = Nothing
            theWorkbook = Nothing
            oWorkbooks = Nothing
            MyExcel = Nothing
        End Try
    End Sub