Macro problem: Abortion when trying to save on existing filename

S

Snoopy

Hey guys
EXCEL-VBA Problem
When using

ActiveWorkbook.SaveAs Range("x1").Value
ActiveWorkbook.Close

- its ok when the file/filename specified in range X1 not exists, but
if the file allready exist,a standard windows messageboard "Replace
file? "YES" "NO" "EXIT appears.
When I choose "YES" the macro works and the file is replaced.
When I choose "NO" or "EXIT" my macro crashes.
How can I make my macro by-pass this and just abort whithout crashing?

Hopefully regards
Snoopy
 
R

Ron de Bruin

Hi Snoopy

If you always want to overwrite use

Application.DisplayAlerts = False
'Save code
Application.DisplayAlerts = True

If you want to use the No option test if the file exist with Dir and do what you want

If Dir("Filepathname") <> "" Then
 
S

Snoopy

Hi Snoopy

If you always want to overwrite use

Application.DisplayAlerts = False
'Save code
Application.DisplayAlerts = True

If you want to use the No option test if the file exist with Dir and do what you want

  If Dir("Filepathname") <> "" Then

--

Regards Ron de Bruinhttp://www.rondebruin.nl/tips.htm








– Vis sitert tekst –

Thanks a lot Ron :)
Regards
Snoopy
 

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