I have functions that open Office Apps, including Word, Excel, and Project. I've had the problem that sometimes when errors occur the Apps are not properly closed and that ruins the function until I either close the App process in Task Manager, or reboot the system.
To this end, I want to close the App in the On Error code at the end of my functions. The problem is, I don't know if the error occurs before or after the application is opened. I know I can Set prjApp1 = Nothing, but that does not close the app. If I use prjApp1.Quit, then I'm afraid I will run into situations where prjApp1 hasn't been created yet, or even Dim'ed, thus resulting in an error.
1. Is there a way to check if a variable has been Dim'ed yet? That is, check if a variable even exists, so I would have to use the name in the check even though it sometimes hasn't been mentioned yet.
2. What's the best way to make sure the App process has been ended in the On Error Goto code? Also, I have to consider the possibility that the user had the App open with another document before activating the function, in which case I don't want to close the app if they were working on something else totally unrelated.
To this end, I want to close the App in the On Error code at the end of my functions. The problem is, I don't know if the error occurs before or after the application is opened. I know I can Set prjApp1 = Nothing, but that does not close the app. If I use prjApp1.Quit, then I'm afraid I will run into situations where prjApp1 hasn't been created yet, or even Dim'ed, thus resulting in an error.
1. Is there a way to check if a variable has been Dim'ed yet? That is, check if a variable even exists, so I would have to use the name in the check even though it sometimes hasn't been mentioned yet.
2. What's the best way to make sure the App process has been ended in the On Error Goto code? Also, I have to consider the possibility that the user had the App open with another document before activating the function, in which case I don't want to close the app if they were working on something else totally unrelated.