BillDickenson
IS-IT--Management
I have a table that I exported from Access to Excel. Now I need to set up a subtotal on the table. I was hoping to use the excel subtotal command and created a macro. However, it just doesn't work. I've tried about 4 other techniques without any luck. Searched a few different topics. I get a variation on "Runtime Error 91. Object Variable or With block variable not set". I've tried setting to a couple of things, even fully qualified it. No luck. I'm obviously missing something very basic. Here is the code
Public Function subTotalArea()
'Public Function subTotalArea(iRows as Integer, ifilename as String)
'comment out the way it's called so we can test
'Create Excel Objects
Dim xlApp As Object
Dim xlWB As Object
Dim xlWS As Object
Dim mydb As Database
Dim szSheetName As String
Dim iRows As Integer
Dim ifilename As String
szSheetName = "Summary"
'Comment these out for Production
iRows = 8
ifilename = "C:\Ops\Test\R-1-MODZILLA.xls"
On Error Resume Next
Set xlApp = GetObject(, "Excel.Application")
If TypeName(xlApp) = "Nothing" Then
'Excel was not open
Set xlApp = CreateObject("Excel.Application")
End If
On Error GoTo 0
Set xlWB = xlApp.WorkBooks.Open(ifilename)
xlApp.Visible = True
With xlWS
.Range("C16:Q16").Cells(index, 0).Select
.Selection.Subtotal GroupBy:=1, Function:=xlSum, TotalList:=Array(4, 5, 6, 7, _
8, 9, 10, 11, 12, 13, 14, 15), Replace:=True, PageBreaks:=False, SummaryBelowData _
:=True
End With
End Function
Someone want to clue me in ? This is driving me a bit nuts.
Public Function subTotalArea()
'Public Function subTotalArea(iRows as Integer, ifilename as String)
'comment out the way it's called so we can test
'Create Excel Objects
Dim xlApp As Object
Dim xlWB As Object
Dim xlWS As Object
Dim mydb As Database
Dim szSheetName As String
Dim iRows As Integer
Dim ifilename As String
szSheetName = "Summary"
'Comment these out for Production
iRows = 8
ifilename = "C:\Ops\Test\R-1-MODZILLA.xls"
On Error Resume Next
Set xlApp = GetObject(, "Excel.Application")
If TypeName(xlApp) = "Nothing" Then
'Excel was not open
Set xlApp = CreateObject("Excel.Application")
End If
On Error GoTo 0
Set xlWB = xlApp.WorkBooks.Open(ifilename)
xlApp.Visible = True
With xlWS
.Range("C16:Q16").Cells(index, 0).Select
.Selection.Subtotal GroupBy:=1, Function:=xlSum, TotalList:=Array(4, 5, 6, 7, _
8, 9, 10, 11, 12, 13, 14, 15), Replace:=True, PageBreaks:=False, SummaryBelowData _
:=True
End With
End Function
Someone want to clue me in ? This is driving me a bit nuts.