Help with ActiveWorkbook.SaveAs

  • Thread starter Thread starter Martin X.
  • Start date Start date
M

Martin X.

Hello,

The line below saves the current workbook, but errors if I have an existing
workbook with the same name already. Is there an additional parameter that
will overwrite the existing workbook with this new one? If not, how should I
go about overwriting the existing workbook? I could put some code in to
check if the workbook name already exist and name the new workbook
appropriately, but I wanted to see if there was something simpler. Thanks.

objExcel.ActiveWorkbook.SaveAs strOutputFilePath
 
Try something like:

On Error Resume Next
Kill strOutputFilePath
On Error Goto 0
objExcel.ActiveWorkbook.SaveAs strOutputFilePath

This will delete the file named by strOutputFilePath if it exists and then
does the SaveAs. Note that Kill permanently deletes the file. It does not
send it to the Windows Recycle Bin. If you want to Recycle the file, see
http://www.cpearson.com/excel/recycle.htm .


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting
www.cpearson.com
(email on the web site)
 
Back
Top