Thanks for the replies. I cannot get Swi's to work with Oracle. I did not succeed with snehakevin's because I do not have the QueryTable function installed on my machine.
I show the code I am using below. Its a pretty blunt force way of doing it. I have one big problem with it (besides speed). The first time it runs, I can see the spreadsheet as it fills. Then next time, I get only the Excel top bar and cell editor. When it asks me to save on quit the second time, I cannot see what I am saving. I assume there is a memory problem, but I think I am unloading Excel, so I don't understand why the difference in runtime actions exists. Any suggestions?
Code:
Private Sub cmdExport_Click()
ml_cmd.CommandText = "select * from facility_profile"
Set mrsFacility = ml_cmd.Execute
mrsFacility.MoveFirst
Dim i As Integer
Dim j As Integer
Dim xlApp As Object
Dim xlBook As Object
Dim xlSheet As Object
On Error GoTo NeedToLoadExcel
Set xlApp = Excel.Application 'use Excel in memory if already loaded
GoTo ExcelAlreadyLoaded
NeedToLoadExcel:
Set xlApp = New Excel.Application 'use NEW keyword to load Excel if not loaded
ExcelAlreadyLoaded:
On Error GoTo DoneExcel
If xlApp.Visible = False Then xlApp.Visible = True
i = xlApp.Workbooks.Count
If i = 0 Then
Set xlBook = xlApp.Workbooks.Add
End If
'get rid of all but one worksheet
xlApp.DisplayAlerts = False
If xlApp.Visible = False Then xlApp.Visible = True
i = xlBook.Worksheets.Count
For i = xlBook.Worksheets.Count To 2 Step -1
xlBook.Worksheets(i).Delete
Next i
xlApp.DisplayAlerts = True
Set xlSheet = xlBook.Worksheets(1)
xlSheet.Name = "Facility Profile"
With xlSheet
For i = 1 To mrsFacility.Fields.Count
With .Cells(1, i)
.Formula = mrsFacility.Fields(i - 1).Name
.Font.Bold = True
End With
Next i
End With
i = 1
Do Until mrsFacility.EOF = True
i = i + 1
For j = 1 To mrsFacility.Fields.Count
xlSheet.Cells(i, j).Formula = mrsFacility.Fields(j - 1).Value
Next j
mrsFacility.MoveNext
Loop
DoneExcel:
xlApp.Quit
Set xlApp = Nothing
Set xlBook = Nothing
Set xlSheet = Nothing
End Sub
Thanks,
Jax