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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Stop Excel Closing 1

Status
Not open for further replies.

SaturnSeven

Programmer
Aug 4, 2005
40
GB
I have a procedure in Access that uses the CreateObject to create a Excel spreadsheet and then some tweaking etc, that works fine. My problem is that as soon as the procedure ends it closes Excel down, when I don't want it to.

Is there a way to stop this from happening ?
Any help would be greatly appreciated.
 


Hi,

Would you please post your code?


Skip,

[glasses] [red]Be Advised![/red]
A wee deranged psychic may be runnin' around out there!
SMALL MEDUIM @ LARGE[tongue]
 
Here's the Code so far,

Sub OpenOrders()

'SetUp
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("qry OpenOrders")
Set xlSheet = CreateObject("Excel.Sheet")
Set xlApp = xlSheet.Application
xlApp.Visible = True

'Data Columns
For Cols = 1 To rst.Fields.Count
xlApp.cells(1, Cols) = rst.Fields(Cols - 1).Name
Next Cols

'Data Fill
xlApp.Range("A2").CopyFromRecordset rst

'Format
With xlApp
.Sheets("Sheet1").Name = "Data"
.Rows("2:2").Select
.ActiveWindow.FreezePanes = True
End With
End Sub
 
I'd try to replace this:
Set xlSheet = CreateObject("Excel.Sheet")
Set xlApp = xlSheet.Application
with this:
Set xlApp = CreateObject("Excel.Application")
Set xlSheet = xlApp.Workbooks.Add().ActiveSheet

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top