HI,Friends
following way i have been generating excel sheet .and i have been
using late binding so that it works will all version of excel sheet.
but most of time i am getting application defined or object defined
error .let me know please any help would be highly appreciated.
i have doubt the following line .because i have been using late binding
Set wb = excl.Workbooks.Add
Set ws = wb.Worksheets(1)
excl.Visible = True
excl.UserControl = True
[Code]
following is the WriteExcel() method to generate excel sheet .
![Name: 1.jpg
Views: 50
Size: 21.6 KB]()
following way i have been generating excel sheet .and i have been
using late binding so that it works will all version of excel sheet.
but most of time i am getting application defined or object defined
error .let me know please any help would be highly appreciated.
i have doubt the following line .because i have been using late binding
Set wb = excl.Workbooks.Add
Set ws = wb.Worksheets(1)
excl.Visible = True
excl.UserControl = True
[Code]
following is the WriteExcel() method to generate excel sheet .
Code:
Public Sub WriteExcel()
Dim Orclsale As New Sale
'Dim excl As New Excel.Application
'Dim wb As Excel.Workbook
'Dim ws As Excel.Worksheet
Dim excl As Object 'late binding for all version of excel sheet
Dim wb As Object 'late binding for all version of excel sheet
Dim ws As Object 'late binding for all version of excel sheet
Dim x As Integer
Dim rowno As Integer
Dim ExclColName(11) As String
ExclColName(0) = "Post Date"
ExclColName(1) = "Dept"
ExclColName(2) = "Deptname"
ExclColName(3) = "StoreName"
ExclColName(4) = "Location"
ExclColName(5) = "Item Parent"
ExclColName(6) = "SKU"
ExclColName(7) = "Units"
ExclColName(8) = "Retail"
ExclColName(9) = "Cost"
ExclColName(10) = "Item Desc"
Set excl = CreateObject("Excel.application")
Set wb = excl.Workbooks.Add
Set ws = wb.Worksheets(1)
excl.Visible = True
excl.UserControl = True
If Not OpenRMSConnection(cnrms) Then Exit Sub
For x = 0 To 11
ws.Range("A1").Offset(0, x).Value = UCase(ExclColName(x)) 'printing header of excel sheet
ws.Range("A1:K1").Interior.Color = vbYellow
Next
rowno = 2
For Each Orclsale In m_SalesColl 'Time to Pull from the m_salesColl and fill in the Worksheet
ws.Cells(rowno, 1) = Orclsale.PostDate
ws.Cells(rowno, 2) = Orclsale.Dept
ws.Cells(rowno, 3) = Mid(Orclsale.DeptName, 8, Len(Orclsale.DeptName) - 7)
ws.Cells(rowno, 4) = Orclsale.StoreName
ws.Cells(rowno, 5) = Orclsale.Location
ws.Cells(rowno, 6) = Orclsale.ItemParent
ws.Cells(rowno, 7) = Orclsale.SKU
ws.Cells(rowno, 8) = Orclsale.Unit
ws.Cells(rowno, 9) = Orclsale.Retail
ws.Cells(rowno, 10) = Orclsale.Cost
ws.Cells(rowno, 11) = Orclsale.ItemDesc
rowno = rowno + 1
Next
Debug.Print m_SalesColl.Count & " =rows are written " 'Finished written all the data in the excel sheet
ws.Application.DisplayAlerts = False
ws.Cells.EntireColumn.AutoFit
ws.Cells.Select
ws.Range("A2").Select
End Sub