View Full Version : Access to Excel and Modify


Colby
11-13-2006, 06:40 AM
I know this is common but I can't find much on my issue. I am exporting a query to excel, opening the app and then formatting. It works - but only the first pass thru.
The user selects which query to export
Thanks to ghudson - user then chooses where to save the file
After this I have fx call to modify the newly created file. This works perfect in other apps but I have added the below code and now it only works on the first pass.
I have been working on this for a few days now - I need help :)

Error Message: 91 - Object variable or With block variable not set

Set xlApp = CreateObject("Excel.Application")
Set xlSheet = xlApp.Workbooks.Open(sFile).Sheets(1)
With xlApp
.Application.DisplayAlerts = False
more code
Select Case Forms("frm_Main").opt_Export.Value
Case 1 'audit selected
.Application.Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
.Application.Selection.FormatConditions.Delete
.Application.Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=OR(TRIM($J1)=""Bas"",TRIM($J1)=""384"",TRIM($J1)=""3m"",TRIM($J1)=""5m"",TRIM($J1)=""10M"",Trim($A1)=""disco"",TRIM($A1)=""never"")"
.Application.Selection.FormatConditions(1).Interio r.ColorIndex = 36
.Application.Range("A1").Select
Case 2 'sales selected
.Application.Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
.Application.Selection.FormatConditions.Delete
.Application.Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=OR(TRIM($J1)=""Bas"",TRIM($J1)=""384"",TRIM($J1)=""3m"",TRIM($J1)=""5m"",TRIM($J1)=""10M"",Trim($A1)=""disco"",TRIM($A1)=""never"")"
.Application.Selection.FormatConditions(1).Interio r.ColorIndex = 36
.Application.Range("A1").Select
End Select

In debug it blows on the .application statement after the Case

Any help is greatly appreciated -thanks

Colby
11-13-2006, 11:39 AM
** bump **