Thank you for taking the time to read my question.
I am developing a small application to do the following:
- Read each .xlsm Report in a specific directory
- Grab specific field based on different Report types
- Store the fields in a custom class object
- Store the custom class object in a List<>
- After reading all the .xlsm Reports, create a new Tally Report from a template
- Output the data from each custom class object in the List<> to the new Tally Report
This is working great. But I added a new feature so that if an exception error occurred, I could prompt the user using a custom message box to either Edit or Remove the document or Ignore the exception and continue getting the remaining data.
When the user selects "Edit", it calls a class file that dynamically generates a new Form, add a DSO Framer Control to the new Form, and then opens a specific file from the parameter passed in.
The first time I receive my message box and select "Edit", it will open the new form correctly and display the .xlsm report for me to edit. Once I click Close, it saves the changes and continues on processing. If I receive my message box a second time and select "Edit" (whether for the same .xlsm file or not) I received an Exception:
"Exception has been thrown by the target of an invocation."
I thought it may have been because the document had already been open using "Microsoft.Office.Interop.Excel", but the first .xlsm file will open even though it had been opened using "Microsoft.Office.Interop.Excel". I did notice that When using "Microsoft.Office.Interop.Excel" I still had an Excel process running in Task Manager after calling the Excel.Application.Quit() function and using Marshal.ReleaseComObject on the ExcelApp object.
If I complete close the application and reopen it, I can "Edit" again the first document that prompts my message box.
All I need is to be able to do when I select the "Edit" option is to pause the running code, display the file for the user to edit, and once they're done editing continue running the code again.
Please advise.
I just tried posting the code in here too and it said I used too many lines. Whats the best way to share all of my code?