Hi Roy. You've helped me before...many times... thanks in advance.
Actually, My earlier post was pretty much the guts of it. If you want.... I can post the entire code, although, its over 100 lines. I'll remove the Call Shell... but it seems to like it.
The other thread is involving the same chunk of code that is being contankerous and evil. The range that I'm copying is not empty, rather, completely filled with data (which is why I'm copying it). I Save, then close the Spreadsheet, then open the next spreadsheet and paste. That took care of the problem...
I've double checked every Range Selection to ensure it was followed by a copy or delete instead of just a select range.
Next I've removed the Call Shell.
Call Shell("c:\program files\microsoft office\office\excel.exe")
When I remove the Call shell, the app fails as soon as it gets to the the Data-Sort
xlapp02.Range("B1:F96").Select
xlapp02.Selection.Sort Key1:=Range("B2"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
But when I put the Call Shell back in, the app runs, as long as there are no other instances of Excel in memory. Below is my entire chunk of code:
Private Sub cmdOpenExcel_Click()
Call Shell("c:\program files\microsoft office\office\excel.exe")
Open_CustSvcRpt 'run sub which opens the CustSvcRpt.xls spreadsheet.
' OPEN AND MANIPULATE CustSvcRpt.xls
xlapp02.Windows("CustSvcRpt.xls").Activate
'ActiveWindow.WindowState = xlNormal
'ActiveWindow.WindowState = xlNormal
xlapp02.Sheets("Sheet1").Select
xlapp02.Sheets.Add
xlapp02.Sheets("Sheet1").Select
xlapp02.Cells.Select
xlapp02.Selection.Copy
xlapp02.Sheets("Sheet2").Select
xlapp02.Range("A1").Select
xlapp02.Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
xlapp02.Columns("C:F").Select
xlapp02.Selection.Delete Shift:=xlToLeft
xlapp02.Columns("D:G").Select
xlapp02.Selection.Delete Shift:=xlToLeft
xlapp02.Columns("E:H").Select
xlapp02.Selection.Delete Shift:=xlToLeft
xlapp02.Columns("E:Z").Select
xlapp02.Selection.Delete Shift:=xlToLeft
xlapp02.Columns("F
").Select
xlapp02.Selection.Delete Shift:=xlToLeft
xlapp02.Columns("G:IV").Select
xlapp02.Selection.Delete Shift:=xlToLeft
xlapp02.Rows("1:57").Select
xlapp02.Selection.Delete Shift:=xlUp
xlapp02.ActiveWindow.SmallScroll Down:=9
xlapp02.Rows("18:36").Select
xlapp02.Selection.Delete Shift:=xlUp
xlapp02.ActiveWindow.SmallScroll Down:=66
xlapp02.Rows("82:100").Select
xlapp02.Selection.Delete Shift:=xlUp
xlapp02.ActiveWindow.SmallScroll Down:=15
xlapp02.Rows("98:130").Select
xlapp02.Selection.Delete Shift:=xlUp
xlapp02.ActiveWindow.SmallScroll Down:=-129
xlapp02.Range("B1").Select
xlapp02.ActiveCell.FormulaR1C1 = "1"
xlapp02.Range("C1").Select
xlapp02.ActiveCell.FormulaR1C1 = "2"
xlapp02.Range("D1").Select
xlapp02.ActiveCell.FormulaR1C1 = "3"
xlapp02.Range("E1").Select
xlapp02.ActiveCell.FormulaR1C1 = "4"
xlapp02.Range("F1").Select
xlapp02.ActiveCell.FormulaR1C1 = "5"
'xlapp02.Range("B1").Select
'xlapp02.Selection.Sort Key1:=Range("B2"), Order1:=xlAscending, Header:=xlGuess, _
'OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
xlapp02.Range("B1:F96").Select
xlapp02.Selection.Sort Key1:=Range("B2"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
xlapp02.Rows("50:6705").Select
xlapp02.Selection.Delete Shift:=xlUp
xlapp02.ActiveWorkbook.Save
'Close_CustSvcRpt 'close CustSvcRpt.xls spreadsheet
'Windows Clipboard has copied materials for pasting.
open_MTD_Snapshot
xlApp.Worksheets("Daily").Activate
xlApp.Range("B6:B53").Select
xlApp.Selection.ClearContents
xlApp.Range("C6:C53").Select
xlApp.Selection.ClearContents
xlApp.Range("D6
53").Select
xlApp.Selection.ClearContents
xlApp.Range("F6:F53").Select
xlApp.Selection.ClearContents
xlApp.ActiveWorkbook.Save
xlapp02.Range("C2:E49").Select
xlapp02.Selection.Copy
xlApp.Range("B6").Select
xlApp.ActiveSheet.Paste
xlApp.ActiveWorkbook.Save
xlapp02.Range("F2:F49").Select
xlapp02.Selection.Copy
xlApp.Range("f6").Select
xlApp.ActiveSheet.Paste
xlApp.ActiveWorkbook.Save
'COPY THE DATA TO THE "DailyData" worksheet for import into Access
xlApp.Range("A6:G53").Select
xlApp.Selection.Copy
xlApp.Worksheets("DailyData").Select
xlApp.ActiveWindow.SmallScroll Down:=-11
xlApp.Range("A2").Select
xlApp.Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
xlApp.ActiveWorkbook.Save
wb.Close
wb02.Close
Set ws = Nothing
Set ws02 = Nothing
Set wb = Nothing
Set wb02 = Nothing
xlApp.Application.Quit
xlapp02.Application.Quit
Set xlApp = Nothing
Set xlapp02 = Nothing
'Run Append query with links to the MTD xls Report and appends to the DATA table.
DoCmd.SetWarnings False
DoCmd.OpenQuery "qryAPP_Append_CustInfo_Input_Date", acViewNormal, acEdit
'Data area in Excel is linked to Access, via append query
'data is appended to Access table.
DoCmd.SetWarnings True
'DoCmd.Quit acQuitSaveNone
End Sub
Public Sub Open_CustSvcRpt()
Set xlapp02 = CreateObject("Excel.Application")
Set wb02 = xlapp02.Workbooks.Open("s:\0-Defa~1\Symposium\CustSvcRpt.xls", False, False)
xlapp02.Visible = True
End Sub
Public Sub open_MTD_Snapshot()
Set xlApp = CreateObject("Excel.Application")
Set wb = xlApp.Workbooks.Open("s:\0-Defa~1\Symposium\Cust_Serv_MTD_Snapshot.xls", False, False)
xlApp.Visible = True
End Sub
I'm stumped.....
![[ponder] [ponder] [ponder]](/data/assets/smilies/ponder.gif)