Make sure you have the microsoft excel 9.0 object library reference set in your project. Here is some additional code that might help you interact with excel:
Dim xlapp As Excel.Application, wrkbk As Excel.Workbook, wrkst As Excel.Worksheet
Dim PathandNameofFile as string, WorkSheetNumber as Integer
I got some help here with this as well. check out the below code. I made some corredtions based on what I was doing. But this basically extracts a recordset from VB and puts it into an excel spread sheet. you can do this from a datagrid, form or list.
Dim objExcel As Excel.Application
On Error Resume Next
Set objExcel = GetObject(, "Excel.Application"
If Err.Number <> 0 Then
Set objExcel = CreateObject("Excel.Application"
End If
Err.Clear
rs.MoveFirst
s = 0
r = rs.Fields.Count
RowNum = 0
Do While (rs.EOF = False)
s = s + 1
RowID = Trim(s)
For ColIdx = 1 To r
ColSet = Int((ColIdx - 1) / 26)
If (ColSet = 0) Then
ColId = Chr(ColIdx + 64)
Else
ColId = Chr(ColSet + 64) & Chr((ColIdx - (ColSet * 26)) + 64)
End If
objExcel.Range(ColId & RowID).Value = rs.Fields(ColIdx - 1)
Next ColIdx
rs.MoveNext
Loop
The code i have is very long so I just gave you the starting point. what you can do as well is, create a macro within excel and copy the code and paste it into VB. Thats why my code is so long. you can format cells etc.
Many thanks to jeepxo, barryna and dvannoy. With your combined responses I believe I have a good basis to get started with.
My application involves creating a spreadsheet from highly variable input, inserting totals and hopefully other things such as background colors, and also loading graphics.
I'll post back into this forum if I learn anything that I think might help anyone else.
This is really an effecive site. Thanks again for your willingness to help a stranger.
John Kisner
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.