• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 309
  • Last Modified:

File SaveAs, replacing existing one if it exists

This code kicks back asking if I want to overwrite the existing file with the same name.  How do I tell it yes.  and do it every time?  Please advise and thanks. -R-

myDirECTorY = "C:\_SAP\ShortageRpt\DefaultExtractFiles\"        'Wherever you want
'myFileNameO = myDirECTorY & Format(Now(), "yyyymmdd_hhmm") & " ZSHORTV2DataCurrent" & ".xlsx"    'File name as desired.
myFileNameO = myDirECTorY & " ZSHORTV2DataCurrent" & ".txt"    'File name as desired.


'Add text to column here

ActiveWorkbook.SaveAs Filename:=myFileNameO, FileFormat:= _
      xlOpenXMLWorkbook, CreateBackup:=False
MsgBox (" Done file saved ")

Open in new window

1 Solution
dsackerContract ERP Admin/ConsultantCommented:
Before your SaveAs, add this line of code:
Application.DisplayAlerts = False
After your SaveAs, add this line of code:
Application.DisplayAlerts = True
RWayneHAuthor Commented:
Thanks, worked nicely. -R-
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now