I posted this on another forum but haven't gotten any results so I'm hoping I'll have better luck here. I have an Access DB that exports data to Excel, including images and documents that I insert using OLEObjects.Add. This is my first time using this function and it has been a learning process but after countless iterations, I have it 'mostly' working. The end result spreadsheet is what I want, however when there is an Excel spreadsheet that is being inserted into the target spreadsheet, the process creates (and leaves open) multiple instances of Excel - two additional instances for each inserted Excel sheet. The additional instances do not have any worksheets open but they are active, meaning I can navigate menus, etc. This does not happen for other Office documents or PDFs, only Excel files. And what's even more strange is that I am unable to close several of the instances after the process completes.
Here is the code I'm using to insert the files:
Here is a screenshot where there were 6 files that were inserted into the export spreadsheet; 3 Excel files, one Word doc, one PDF and one PPT. Excel was closed before the export, and the screenshot shows 7 instances were running after the process completed.
If I try to close any of the 7, it asks me if I want to save the changes to the export spreadsheet (Book5 in this case). After saving (or discarding), 4 of the instances close and I am left with "ExcelTest2.xlsx", "Excel" and "Book1.xlsx" in this example. I am unable to close any of those without forcing it in Task Manager. However, if I open a new (unrelated) Excel file and close it, two of the instances disappear and if I repeat that process, the third one disappears.
Any ideas on what I can do to either prevent the extra instances from opening or somehow close them? I want to leave the main spreadsheet open so that the user can review it. Thanks in advance for any help!
Here is the code I'm using to insert the files:
VBA Code:
Dim xlApp As Excel.Application 'Open the Excel application
Dim xlBook As Excel.Workbook 'Create a new Excel workbook
Dim xlImg As Excel.Worksheet 'Create a tab with Attachment details
Set xlApp = Excel.Application
Set xlBook = xlApp.Workbooks.Add
'First I add a 'data only' worksheet and do some processing on it, then add a new sheet below for the attachments
xlBook.Worksheets.Add
Set xlImg = xlBook.Worksheets(1)
'I get the filename from a recordset
'strIcon is the default executable for the file type
'strAtchName is the file name without the path
xlBook.ActiveSheet.OLEObjects.Add(FileName:=<recordset filename>, _
Link:=False, DisplayAsIcon:=True, IconFileName:=strIcon, _
Left:=ActiveSheet.Range("D" & x).Left, Width:=13, _
Top:=ActiveSheet.Range("D" & x).Top, Height:=56, _
iconlabel:=strAtchName).Select
'More formatting, then cleanup
Here is a screenshot where there were 6 files that were inserted into the export spreadsheet; 3 Excel files, one Word doc, one PDF and one PPT. Excel was closed before the export, and the screenshot shows 7 instances were running after the process completed.
If I try to close any of the 7, it asks me if I want to save the changes to the export spreadsheet (Book5 in this case). After saving (or discarding), 4 of the instances close and I am left with "ExcelTest2.xlsx", "Excel" and "Book1.xlsx" in this example. I am unable to close any of those without forcing it in Task Manager. However, if I open a new (unrelated) Excel file and close it, two of the instances disappear and if I repeat that process, the third one disappears.
Any ideas on what I can do to either prevent the extra instances from opening or somehow close them? I want to leave the main spreadsheet open so that the user can review it. Thanks in advance for any help!