Set Range in Excel with Access 2007

River34

New member
Local time
Today, 10:11
Joined
Mar 27, 2012
Messages
4
I have searched out this question for 2 days. Lots of examples that work for people but still fail when I use them. I have a basic un-understanding of objects. I need to manipulate an Excel spreadsheet to delete the str value cells (""). I am getting sooooo frustrated. Below is code I'm using and failure point:

Dim DateStart As Date
Dim DateEnd As Date
Dim jvCol As String
Dim field As DAO.Fields
Dim appExcel As Excel.Application
Dim wkbk As Excel.Workbook
Dim ExcelSht As Excel.Sheets

Set db = CurrentDb()

'This will transfer the query, prompt for name and directory, and open the file
DoCmd.OutputTo acOutputQuery, "qry_DashboardUnion", _
acFormatXLS, , True


'Open Excel
On Error Resume Next
Set objExcel = GetObject(, "Excel.Application")
If Err = 429 Then
Set objExcel = CreateObject("Excel.Application")
End If
On Error GoTo 0

'Open Excel file to update the data tabs
With objExcel
.Visible = True
.Sheets("qry_DashboardUnion").Select
' Dim Range As objExcel.ExcelSht.Range

'*********************************************************************************
.Columns("A:A").Select
.ActiveWorkbook.Worksheets("qry_DashboardUnion").Sort.SortFields.Clear
.ActiveWorkbook.Worksheets("qry_DashboardUnion").Sort.SortFields.Add Key:= _
.Range("A1:A64"), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:= _
xlSortNormal
With .ActiveWorkbook.Worksheets("qry_DashboardUnion").Sort
.SetRange .Range("A2:A64")
.Header = xlNo
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
.Columns("B:B").Select
.ActiveWorkbook.Worksheets("qry_DashboardUnion").Sort.SortFields.Clear
.ActiveWorkbook.Worksheets("qry_DashboardUnion").Sort.SortFields.Add Key:= _
.Range("B1"), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:= _
xlSortNormal
With .ActiveWorkbook.Worksheets("qry_DashboardUnion").Sort
.SetRange .Range("B2:B64")
.Header = xlNo
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With

This fails on the .SetRange .Range("A2:A64") line.
Error Message - Object doesn't support this property or method.

I can do all of the other manipulation with this file but set this darn range. Can anyone tell me what I need to set as an object to get this code working? I sure would appreciate the help. Thanks!
 

Users who are viewing this thread

Back
Top Bottom