Macro entry to choose "yes"

Jimmy59601

New Member
Joined
Sep 21, 2017
Messages
7
I used the Record Macro feature in Excel 2013 to create a macro to do a Save as of a workbook to another file. However, the macro stops at the point where I'm prompted to replace the existing file, where I would click "yes." I copied the code below, and perhaps someone can tell me how to make the macro enter "yes" and then exit Excel. I want to save a file named z-Bank.xlsx as x-Bank.xlsx Thanks!

Sub SaveAS()
'
' SaveAS Macro
'
' Keyboard Shortcut: Ctrl+s
'
ChDir "W:"
ActiveWorkbook.SaveAS Filename:="W:\x-Bank.xlsx", FileFormat:= _
xlOpenXMLWorkbook, CreateBackup:=False
End Sub
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Try:

Code:
Sub SaveAS()
'
' SaveAS Macro
'
' Keyboard Shortcut: Ctrl+s
'
ChDir "W:"
[COLOR=#0000ff]Application.DisplayAlerts = False[/COLOR]
ActiveWorkbook.SaveAS Filename:="W:\x-Bank.xlsx", FileFormat:= _
xlOpenXMLWorkbook, CreateBackup:=False
[COLOR=#0000ff]Application.DisplayAlerts = True[/COLOR]
End Sub
 
Last edited:
Upvote 0
Try this:
Code:
Sub SaveAS()
'
' SaveAS Macro
'
' Keyboard Shortcut: Ctrl+s
'
ChDir "W:"
Application.DisplayAlerts = False
ActiveWorkbook.SaveAS Filename:="W:\x-Bank.xlsx", FileFormat:= _
xlOpenXMLWorkbook, CreateBackup:=False
Application.DisplayAlerts = True
Application.Quit
End Sub
 
Upvote 0
I'm afraid it no longer "saves as," and still won't exit Excel. The macro apparently completes, but the first workbook remains open.
 
Upvote 0
So your now saying you have more then one workbook open? I never saw that in your original script. What do you want to do with the second workbook?
I'm afraid it no longer "saves as," and still won't exit Excel. The macro apparently completes, but the first workbook remains open.
 
Upvote 0
So your now saying you have more then one workbook open? I never saw that in your original script. What do you want to do with the second workbook?

Sorry for the confusion. No, only one workbook is open: z-Bank.xlsx. After I run the latest code, it stays open and the Save as does not work, in that the target of the Save as does not update.
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,157
Members
453,021
Latest member
Justyna P

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