I created a function to open any valid file now I want to close the opened file. Input file could be of any valid file type: .docx, .bmp, xlsx, etc.
I was trying to make WScript
object and trying to close file using below code, but it's not working.
Public Function openfile(filepath)
Set ws = CreateObject("WScript.Shell")
ws.Run filepath
'taking the screen shot of opened file
End function
Public Function closefile(filepath)
Set ws = CreateObject("WScript.Shell")
ws.AppActivate (filepath)
ws.Terminate
End function
However, I am unable to close the opened file and getting error. File could be any valid file type which I will get to know only at run time. We already have a function to update the opened file for .txt and Excel.
Can anybody help me to find out how I can close already opened file irrespective of file type?