The code below allows a user to select a file and traps the path to that file as a string.
The file is then edited and moved out of the folder which is then left empty.
I want to then delete the folder so as to clean up properly.
A "permission denied" error occurs whenever deletion of said folder is attempted at any time after execution of the line
fFullPATH = CStr(Application.GetOpenFi
eFilter, FilterIndex, Title, ButtonText, MultiSelect))
The folder can be deleted by excel or directly by the windows operating system e.g. windows explorer etc. at any time prior to this and also at any time after excel application is closed (and restarted -as required if deleting the folder programmatically).
How do I release the hook excel has on the folder containing the file?
Const FileExtension_Order = "txt"
Function GetOrderFile() As String
Const sNameProc = "GetOrderFile" 'Specify the Function Name
Dim pdf As Variant
Dim Title As String, fPrefix As String, fFullPATH As String, FileName_New As String, FileName_NewExtended As String 'As String
Dim PDFType ' as Array'As String
Dim N As Integer
Dim StartDirectory As String
Const FilterIndex As Integer = Empty
Const ButtonText = Empty
Const MultiSelect As Boolean = False
Const FileFilter = "Order Files (*." & FileExtension_Order & "),*." & FileExtension_Order & ""
StartDirectory = "C:\temp"
ChDrive Left(StartDirectory, 1)
N = 0
Title = """Double-Click"" the Folder for your job then choose your file..."
N = N + 1
fFullPATH = CStr(Application.GetOpenFilename(FileFilter, FilterIndex, Title, ButtonText, MultiSelect))
If fFullPATH = vbNullString Then
If fFullPATH = "False" Then
If N < 3 Then
MsgBox """Double-Click"" the Folder for your job"
GetOrderFile = fFullPATH