Help with ActiveWorkbook.SaveAs

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
 
C

Chip Pearson

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)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top