Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XL Automation Started Crashing Access

Status
Not open for further replies.

lameid

Programmer
Jan 31, 2001
4,207
0
0
US
Since this is as much Access as Excel I am linking my generic VBA thread here in hopes of gaining more attention [sadeyes]

thread707-1615566
 
The tidy-up is just not part of my code excerpt... It still should run once successfully if I didn't.
 
My experience is that being explicit is the best way of doing automation. This would mean declarate and instantiate objects at least down to sheet level, if sheet level is needed.

And never ever rely on any of the .Activethingies, which is impicit referencing, and might not refer to what you hoped it referred to.

[tt]Set XLAPP = CreateObject("Excel.Application")
'With XLAPP
dim wr as object 'excel.workbook
set wr = xlapp.Workbooks.Open FileName:= _
strFilePath
If strNewPath <> "" Then
wr.SaveAs FileName:=strNewPath _
, FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False


'Bunch of code that manipulates file makes a selection...

' Now - I don't remember which is the parent object of
' the .selection object and the .cells object
' but do declare and instantiate objects, and refer
' through the parent object in stead of the implicit
' referencing you're doing

' you'll most likely also find extra instances of Excel
' in memory after such errors

' now - the below is just OTOH, as I'm not in a position
' to test at the moment, you need to check/find what
' is the parent object of the .selection object and
' the .cells object are, and use them

xlapp.Selection.Sort Key1:=wr.Cells(1, RS!Detail_Column), Order1:=xlAscending, Header:=IIf(RS!Has_Header_Row, xlYes, xlNo), _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal

'More manipulation and saving file etc.

' End With[/tt]

Roy-Vidar
 
Thanks Roy, that was my code hunch but it is good to see some experince behind the thought before taking the time... Hopefully I will get to it today. Unfortunately this is not the only anomalous thing I am looking at <sigh>.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top