you can use APIs findwindow or similar to determine when the dialog is open, then sendmessage to submit a value to it

or if you can return the value (url) of the webquery before submitting the form, you can use urldownloadtofile API