RayFrye
Board Regular
- Joined
- Jan 31, 2005
- Messages
- 129
- Office Version
- 365
- 2019
I process a number of Excel Named Cells and input them into a Word document.
The code runs from Word.
The code below works properly the first time for multiple Excel Named Cells.
The second time I run the code, the code fails opening the Excel Workbook because the Workbook is locked for reading.
(Even this has me stumped because I never write to the Excel file.)
If I close Word and run the code it again, it works fine ONE time.
I believe I am doing everything to release the Excel resources back to Windows but it doesn't appear to work.
Can I buy a clue?
The code runs from Word.
The code below works properly the first time for multiple Excel Named Cells.
The second time I run the code, the code fails opening the Excel Workbook because the Workbook is locked for reading.
(Even this has me stumped because I never write to the Excel file.)
If I close Word and run the code it again, it works fine ONE time.
I believe I am doing everything to release the Excel resources back to Windows but it doesn't appear to work.
Can I buy a clue?
VBA Code:
'Excel is Not Open
Set ExcelApp = CreateObject("Excel.Application")
Set ExcelWorkBook = ExcelApp.Workbooks.Open(ExcelDocumentPath)
'lot's of code here that works fine the first time.
On Error Resume Next 'just to be safe
ExcelWorkBook.FileClose
Set ExcelWorkBook = Nothing
ExcelApp.Application.Quit
Set ExcelApp = Nothing