L
Legacy 15162
Guest
I am dumping data from access into an excel spreadsheet. I am looking to sort the information after this occurs, but I am getting this error.
Application-defined or object-defined error 1004
Here is my code
Private Function ExcelOuterlier()
Dim xlWB As Excel.Workbook
Dim xlApp As Excel.Application
Dim xlWS As Excel.Worksheet
Dim i As Integer
On Error GoTo ftwkshterror
Set xlApp = GetObject(, "Excel.Application")
Set xlWB = xlApp.Workbooks.Open("\\test\Reports\Outerlier Analysis\New Outerlier Report.xls")
For i = 1 To xlWB.Worksheets.Count
Set xlWS = xlWB.Worksheets(i)
If xlWS.Name = "CHAR Outerlier Report" Then
xlWS.Range("B5") = TxtBeginPeriod & " THRU " & TxtEndPeriod
With xlWS.Range("SORTCHAR")
.Sort Key1:=Range("V12"), Order1:=xlAscending, Header:=xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
End With
Else: xlWS.Name = "LA-TX Outerlier Report"
xlWS.Range("B5") = TxtBeginPeriod & " THRU " & TxtEndPeriod
With xlWS.Range("SORTLATX")
.Sort Key1:=Range("V12"), Order1:=xlAscending, Header:=xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
End With
End If
Next i
' if not set to visible, will not show document being manipulated
xlApp.Visible = True
ftwkshterror:
Select Case Err.Number
Case 0
Case 429
Set xlApp = CreateObject("Excel.Application")
Resume Next
Case Else
MsgBox Err.Description & " " & Err.Number
End Select
Application-defined or object-defined error 1004
Here is my code
Private Function ExcelOuterlier()
Dim xlWB As Excel.Workbook
Dim xlApp As Excel.Application
Dim xlWS As Excel.Worksheet
Dim i As Integer
On Error GoTo ftwkshterror
Set xlApp = GetObject(, "Excel.Application")
Set xlWB = xlApp.Workbooks.Open("\\test\Reports\Outerlier Analysis\New Outerlier Report.xls")
For i = 1 To xlWB.Worksheets.Count
Set xlWS = xlWB.Worksheets(i)
If xlWS.Name = "CHAR Outerlier Report" Then
xlWS.Range("B5") = TxtBeginPeriod & " THRU " & TxtEndPeriod
With xlWS.Range("SORTCHAR")
.Sort Key1:=Range("V12"), Order1:=xlAscending, Header:=xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
End With
Else: xlWS.Name = "LA-TX Outerlier Report"
xlWS.Range("B5") = TxtBeginPeriod & " THRU " & TxtEndPeriod
With xlWS.Range("SORTLATX")
.Sort Key1:=Range("V12"), Order1:=xlAscending, Header:=xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
End With
End If
Next i
' if not set to visible, will not show document being manipulated
xlApp.Visible = True
ftwkshterror:
Select Case Err.Number
Case 0
Case 429
Set xlApp = CreateObject("Excel.Application")
Resume Next
Case Else
MsgBox Err.Description & " " & Err.Number
End Select