Export to Excel and overwrite existing file automatically

kmacd6951

Board Regular
Joined
Mar 3, 2004
Messages
58
I am running an Access Query and then I am wanting to save the results of this query as an HTML file. I need to be able to overwrite this file each time I rerun the query.

I set up a Macro to export the Access Data to Excel, and save as an HTML file using the "OutputTo" function, but this is not working because I am getting the pop-up message "Do you want to replace xxx file? Y/N"

I saw in some other posts on newsgroups, that someone suggested using the "SendKeys". I tried to add that in and hit the left arrow and enter keys (for those to be the keys that get sent - to move focus over the YES button and then accept), but it is still not working.

Then I have seen a few other suggest using the KILL function.... I am assuming to do that you need to use VBA, not a Macro.

I have posted the macro, which I had Access convert to VBA, below... Can anyone make suggestions for a way that I can export my results from Access query out to an HTML file that will get overwritten each time I run the query?
Thanks!


Option Compare Database

'------------------------------------------------------------
' Cases_Closed_Comments1
'
'------------------------------------------------------------
Function Cases_Closed_Comments1()
On Error GoTo Cases_Closed_Comments1_Err

DoCmd.OpenQuery "Cases Closed Query - Weekly Comments", acViewNormal,
acEdit
DoCmd.SetWarnings False
DoCmd.Hourglass True
DoCmd.OutputTo acQuery, "Cases Closed Query - Weekly Comments",
"HTML(*.html)", "S:\Groupcast Solution Services\Weekly Comments.htm", False,
"", 0
SendKeys "", True
DoCmd.Close , ""


Cases_Closed_Comments1_Exit:
Exit Function

Cases_Closed_Comments1_Err:
MsgBox Error$
Resume Cases_Closed_Comments1_Exit

End Function



Expand AllCollapse All
Code:
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Re: Export HTML and overwrite existing file automatically

Disregard what I said about Excel... Excel is not included here...
I am wanting to Export my Access results to an HTML file that gets overwritten each time without having to click the YES button...

Thanks
 
Upvote 0
How about simply this:

Kill "S:\Groupcast Solution Services\Weekly Comments.htm"

Put it right at the start of the code.

I'm assuming the name of the file is always the same.
 
Upvote 0

Forum statistics

Threads
1,221,825
Messages
6,162,166
Members
451,750
Latest member
dofrancis

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top