In VBA, I am exporting to a template. My checking goes to the extent of checking if a file exists, and getting permission to overwrite:
However it stumbles if the file is open (Filecopy gets its permission denied)
How do I check if a file is open, and forcibly close it if it is?
Code:
If Dir(sOutput) <> "" Then ' If output file already exists
varConfirmOverwrite = MsgBox("The output file name already exists, would you like to overwrite it?", vbOKCancel, "File Already Exists")
If varConfirmOverwrite <> vbOK Then ' Do not overwrite
GoTo exit_Here
Kill sOutput
Else ' Delete original
Kill sOutput
End If
End If
However it stumbles if the file is open (Filecopy gets its permission denied)
How do I check if a file is open, and forcibly close it if it is?