VBA: Checking and closing an Excel file from Access

Hi Experts!

I have an access program that creates an excel file to log in any errors I have encountered while the program is running (I don't really open the excel file such that it shows in the taskbar). My question is how can I check if the excel file is open (active)? (Meaning it is open and it's in my taskbar) I want to be able to check if it's open and then be able to close the excel file to ensure that I won't get any errors while I use my program. I always end up with something going wrong in the program when the excel file I use is open. Hope I made sense.

Thanks in advance!

rusco
ruscoAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
samopalConnect With a Mentor Commented:
Try this :

Dim xlBook As Excel.Workbook, xlApp As Excel.Application
Set xlBook = GetObject("Your Excel File Name")
Set xlApp = xlBook.Parent
xlBook.Save
xlBook.Saved = True
xlBook.Close
Set xlBook = Nothing
xlApp.Quit
Set xlApp = Nothing

Hope This Helps,
D'Al
0
 
shanesuebsahakarnCommented:
0
 
ruscoAuthor Commented:
Hi D'Al,

Thanks! Your code did exactly what I needed.

shanesuebsahakarn,

Thanks for the reply as well!
0
All Courses

From novice to tech pro — start learning today.