VBA for bypassing the "replace file" prompt when "saving as" a file in a macro

wilcowoods

Active Member
Joined
May 29, 2008
Messages
275
I am setting up a "save as" macro that saves a file by replacing another file in a folder. Even though the macro has been recorded by approving the replacement (the prompt appears "the file --- already exists. Do you want to replace the existing file?"), when I run the macro, I am again prompted about replacing the file. Is it possible to avoid the prompt so the file is automatically saved by replacing the named file?

Any help would be gratefully accepted!

Thanks
Will:confused:
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Hi

Use:

Code:
Application.DisplayAlerts = False

at the start of your code - this ensures that VBA will automatically select the default option when it processes your saveas code (which is to overwrite).

Should you wish to turn alerts back on in your rouine, set DisplayAlerts back to True.
 
Upvote 0
It depends by what you mean "replacing an existing folder" - can you explain some more? Do you want to delete an existing folder, rename it or what?
 
Upvote 0
actually i am creating a folder in c drive and saving few workbooks in it thr macro..... now i want that if that folder (same name) already exist thr it should replace it automatically.
 
Upvote 0
no if it already exist i have to replace it with an empty folder first and then add new updated workbooks into it....... as it might be a case that i had run this macro last month and it contains the last month's information.... now in current month i wanted to create a new folder and add new files into it......
 
Upvote 0
I think you probably want to test for the existence of the folder first, and if found, delete all the files contained within. There are several approaches you could take to do this, the following is just one:

Code:
strDirectory = "C:\Folder\YourFolderOfInterest"
If Dir(strDirectory,vbDirectory)<>"" Then
  'it exists! - now we need to loop thru the files contained within and delete them
  strFile = Dir(strDirectory & "\*.*")
  If strFile<>"" Then
    Do
      Kill strFile
      strFile = Dir
    Loop While strFile<>""
  End If
Else
  'folder does not already exist - proceed with routine
End If

Make sense?
 
Upvote 0
Is there any that <acronym title="visual basic for applications">VBA</acronym> will automatically select the non default option when it processes your saveas code.
i.e. is there any way i change default not to over wright.
Any help ??
Thanks in advance.
 
Upvote 0

Forum statistics

Threads
1,214,957
Messages
6,122,466
Members
449,086
Latest member
kwindels

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