[Resolved] Deleting Rows in Excel via Access
In my code, I am trying to delete a selected set of rows using:
VB Code:
'delete rows
If count > 0 Then
Rows("1:12").Select
Selection.Delete Shift:=xlUp
End If
When ran, it carries out the deletion. However when I close excel/quit the application, an excel instance still remains - until I stop the process.
From reading past posts, this is symtom of incorrect code that works (?)...causing an excel instance to hang. The soluiton is to pin-point the code that is causing this. In my case Rows("1:12").Select is the problem.
Is there another way to delete rows in excel?
:(
Re: Deleting Rows in Excel via Access
You need to post the code you wrote to create the Excel application instance and open the workbook, etc. I see your using
the default objects "Rows" and the "Selection" object. Where are your variable objects that fully qualify them? That is the problem and
you may also not be quiting the app using your Excel application onject. ;)
Re: Deleting Rows in Excel via Access
When referencing Excel objects from Access, use the parent object to get methods/properties. When cutting and pasting from an excel macro, excel omits the parent object (in this case the application object and current sheet)
VB Code:
Dim xlApp As Excel.Application, sheet As Excel.Worksheet
With xlApp
Set sheet = .ActiveWorkbook.Sheets("Header")
'delete rows
If count > 0 Then
sheet.Rows("1:12").Select
.Selection.Delete Shift:=xlUp
End If
end With
Re: Deleting Rows in Excel via Access
Sorry, we posted at the same time.
I finally figured it out myself, and you were right as well. Thanks.
Re: [Resolved] Deleting Rows in Excel via Access
:thumb:'s on solving it. ;)
Its not a waste because some member may do a search or read this thread and it will help them, etc.