Solved

File SaveAs, replacing existing one if it exists

Posted on 2014-01-02
2
288 Views
Last Modified: 2014-01-03
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.

Workbooks.Add
ActiveSheet.Paste

'Add text to column here

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

Open in new window

0
Comment
Question by:RWayneH
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 20

Accepted Solution

by:
dsacker earned 500 total points
ID: 39752947
Before your SaveAs, add this line of code:
Application.DisplayAlerts = False
After your SaveAs, add this line of code:
Application.DisplayAlerts = True
0
 

Author Closing Comment

by:RWayneH
ID: 39753751
Thanks, worked nicely. -R-
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
Learn how to create and modify your own paragraph styles in Microsoft Word. This can be helpful when wanting to make consistently referenced styles throughout a document or template.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question