I have some VBA code that opens a webpage, then calls a javascript function that deletes a file off of the page. When this function is called, it calls a window.confirm in the HTML to make sure that the user really wants to delete the file. The options are yes and cancel. My question- Is there any way to automatically make my VBA code answer yes? As it is, I can automate everything but the “yes” click, which means I still have to sit there and click yes for every file that it wants to delete; it’d be nice to run the code and be able to walk away.
edit: if it helps, here is the code I’m using to execute the javascipt. Also, the javascript function code
My code:
Dim CurrentWindow As HTMLWindowProxy: Set CurrentWindow = IE.Document.parentWindow
m = 2
Do Until date_var < "2011-7-1"
Cells(1, 11).Value = Range("j1") - m
date_var = Cells(1, 11).Value
date_var = Format(date_var, "yyyy-m-d")
Call CurrentWindow.execScript("Delete('filepath_here_" & date_var & ".csv?DELETE')")
Javascript Function:
<SCRIPT LANGUAGE="JavaScript">
function Delete(What)
{
if (window.confirm("Do you really want to delete this file"))
{
location.href = What;
}
}
</SCRIPT>
I don’t know VBA, but try the following script:
That should do the trick. It’s better than calling the delete function directly. No function call overhead, no side effects, and no confirm box. Replace the last line of your code with this one and check.