0

I use this macro to save my workbook:

sNewFilePath = ActiveWorkbook.Path

ActiveWorkbook.SaveAs Filename:=sNewFilePath & "/" &Range("A1")

But if a file already exists, and I "Cancel" or choose "No", I get VBA error. I'm new at VBA, so I cant figure out what and where to add functions to the macro to make it work...

Community
  • 1
  • 1
Alex50
  • 1
  • 2
  • Try searching SO based on your sample code. This looks like a duplicate of https://stackoverflow.com/questions/23936601/how-to-disable-warnings-at-saving – Mike Gorski May 11 '18 at 20:34

1 Answers1

0

Using the function Dir() you can check if a file exist and determine what to do.

Example

if Dir("C:\ScrubRetValFile.txt") = "" Then
    msgbox "File not founded"
else
    msgbox "File founded"
End if

Cheers.

WltrRpo
  • 263
  • 2
  • 13