LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel,microsoft.public.excel.programming,microsoft.public.office.developer.vba,microsoft.public.office.developer.automation,microsoft.public.access.modulesdaovba
external usenet poster
 
Posts: 169
Default Excel won't close properly

I'm using automation to build an Excel workbook and 4spreadsheet from within
Access.

When I'm done building the workbook and the associated worksheets, I want to
leave Excel open for my users, so I don't quit Excel, I just set the objects
to nothing in my code. But when they close Excel upon completion of their
work, it occassionally fails to remove Excel from the running processes, and
subsequent runs of the code mentioned above result in a variety of errors.
The code that initiates the selection/opening of Excel and then sets the
objects to nothing follows. If the problem is not here, then I'll try the
SynchMatrix Page code in my next post.

Public Sub SynchMatrix(FY As Integer, Optional NewWorkbook As Boolean =
True)

Dim xlApp As Excel.Application
Dim xlWbk As Excel.Workbook
Dim xlSht As Excel.Worksheet

Dim intQuarter As Integer
Dim StartDate As Date
Dim EndDate As Date

On Error GoTo ProcError

'Open Excel and create a new workbook
Set xlApp = GetObject(, "Excel.Application ")
xlApp.Visible = True

'If no workbook exists in the current instance of Excel, or the
NewWorkbook variable = true
'then create a new workbook.
'Then select the last workbook in the workbooks collection
If xlApp.Workbooks.Count = 0 Or NewWorkbook = True Then
xlApp.Workbooks.Add
Set xlWbk = xlApp.Workbooks(xlApp.Workbooks.Count)

intQuarter = 1
StartDate = DateSerial(FY - 1, 10, 1)
While StartDate < DateSerial(FY, 10, 1)

If xlWbk.Sheets.Count < intQuarter Then xlWbk.Sheets.Add
After:=xlWbk.Sheets(intQuarter - 1)

Set xlSht = xlWbk.Sheets(intQuarter)
xlSht.Select

'Lock the top two rows for vertical scrolling
xlSht.Range("A3").Select
xlApp.ActiveWindow.FreezePanes = True

'Zoom out so users can see all of the columns being manipulated in
the SynchMatrixPage subroutine
xlApp.ActiveWindow.Zoom = 60

'Change the workbook tab titles
xlSht.Name = intQuarter & Choose(intQuarter, "st", "nd", "rd", "th")
& "_Qtr_FY" & Format(FY, "00")

'Build each page
EndDate = DateAdd("m", 3, StartDate) - 1
Call SynchMatrixPage(xlApp, StartDate, EndDate)

'Go to the next page
intQuarter = intQuarter + 1
StartDate = DateAdd("m", 3, StartDate)

Wend

ProcExit:

If Not xlSht Is Nothing Then Set xlSht = Nothing
If Not xlWbk Is Nothing Then Set xlWbk = Nothing
If Not xlApp Is Nothing Then Set xlApp = Nothing

Exit Sub

ProcError:

If Err.Number = 429 Then 'GetObject failed
Set xlApp = CreateObject("Excel.Application")
Resume Next
Else
MsgBox Err.Number & vbCrLf & Err.Description, , "SynchMatrix"
End If

End Sub


 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
why do all excel worksheets/workbooks close when I close one? Penny Excel Discussion (Misc queries) 1 November 29th 06 03:49 AM
Excel won' close properly Rob Excel Discussion (Misc queries) 2 February 22nd 06 04:27 AM
Not close thead when I close excel wakeup[_3_] Excel Programming 0 December 5th 05 08:57 AM
Excel shoud not close all active books when clicking close button technomike Excel Discussion (Misc queries) 0 June 10th 05 05:35 PM
excel - Windows close button (x) should only close active workboo. CoffeeAdict Setting up and Configuration of Excel 3 February 8th 05 04:30 AM


All times are GMT +1. The time now is 02:02 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"