1. Activate the Excel document indicated by the stored variable excelPID (it does).
2. Make sure the "Tracker" sheet is selected before performing any actions (it does).
3. Sends Ctrl+Shift+q to execute a macro in Excel (it does).
Here is where it stops behaving the way that I think it should.
4. Loop through a specific directory (correctly identified), looking only for xml files.
5. As long as the file is open, it should remain in the loop.
6. Once the file has been indicated as closed, it should delete that file.
The problem is, it does loop through the directory, but... it deletes all files in the directory despite the xml file identifier. Because of this, I think that it breaks the loop (since other files in that directory are not open) and attempts to delete them all. This is not the intended behavior. The reason I have it looping through the directory rather than looking for an actual file name is because the filename is dynamic, though I am not sure what the naming convention is. The format of the filename itself is 12345_678_OfficeAppointments_MyName_901234.xml.
What am I missing? I appreciate any help, as usual.
Code: Select all
^+n::
{
WinActivate("ahk_pid " excelPID)
Xl.Sheets("Tracker").Select
SendInput "^+q"
Loop Files medentDir "*.xml"
{
fileName := StrSplit(A_LoopFileShortName, ".")[1]
while (WinExist("ahk_Title " fileName)) {
Sleep 1000
}
FileDelete A_LoopFileFullPath
fileName := ""
break
}
}