Thanks a lot capricorn1 for your quick response. I'm not an Access or Excel expert, so please bear with me.
The following parameter is not optional -->> xlApp As Excel.Application <<--- What I'm supposed to pass here?
Here is what I'm doing:
Dim xlWorkbook As Excel.Workbook
Set xlWorkbook = Excel.Workbooks.Open("Path
...
... ' changes to the spreadsheet here
...
xlWorkbook.Save
xlWorkbook.Close
Set xlWorkbook = Nothing
If I have one or more instances of Excel open the 'changes to the spreadsheet' don't get saved, instead I get a read-write message.
If I close all running Excel instances and try again, the all the 'changes to the spreadsheet' get saved.
So, I'll I want to do is close all running instances --without knowing their names-- before making 'changes to the spreadsheet'
Thanks a bunch!
Main Topics
Browse All Topics





by: capricorn1Posted on 2006-11-02 at 11:46:23ID: 17860918
Sub Excel_CloseWorkBook(xlApp As Excel.Application, Optional bSaveChanges As Boolean = False)
Dim wb As Excel.Workbook
On Error Resume Next
If xlApp.Name > "" Then
' forces an error if the xlApp object has not been Set
End If
If Err.Number <> 0 Then Exit Sub ' nothing to do.
On Error GoTo 0
For Each wb In xlApp.Workbooks 'Close all open workbooks
wb.Close bSaveChanges
Next wb
xlApp.UserControl = False
Set xlApp = Nothing
End Sub