VBA - How to Save and Close without prompt

luporiman

New Member
Joined
Aug 13, 2009
Messages
11
Hello,

I have the following line of VBA code within one of my macros.


ActiveWorkbook.SaveAs Filename:="C:\LH1\" & flname, _
FileFormat:=xlCSV, CreateBackup:=False

ActiveWorkbook.Close



The macro opens up a new file, copies data into it, saves it as a .CSV, and then closes the .CSV. This is the only command in the macro that saves a file.

I can't get it to stop prompting the user with a "Do you want to save the changes to xxx.csv".

Is there a way to answer that question within the macro so the user is not prompted?
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Maybe try:

Code:
ActiveWorkbook.SaveAs Filename:="C:\LH1\" & flname, _
FileFormat:=xlCSV, CreateBackup:=False
 
ActiveWorkbook.Close true
Or maybe:

Code:
ActiveWorkbook.SaveAs Filename:="C:\LH1\" & flname, _
FileFormat:=xlCSV, CreateBackup:=False
ActiveWorkbook.saved = true
ActiveWorkbook.Close

Hope that helps.
 
Upvote 0
That worked perfectly!

Many thanks for the help!

Code:

ActiveWorkbook.SaveAs Filename:="C:\LH1\" & flname, _FileFormat:=xlCSV, CreateBackup:=FalseActiveWorkbook.saved = trueActiveWorkbook.Close</PRE>
 
Upvote 0
Hi,

I tried the code, but the saveas prompt still come out, can you please help me out? thanks a lot!
here is my code:
New_file_name = Application.GetSaveAsFilename(CellCodeFind, "Microsoft Excel Workbook (*.xls), *.xls")
Application.DisplayAlerts = False
ActiveWorkbook.Saved = True
ActiveSheet.Copy
ActiveWorkbook.SaveAs filename:=New_file_name, FileFormat:=xlNormal, CreateBackup:=False
ActiveWorkbook.Saved = True
ActiveWindow.Close
 
Upvote 0

Forum statistics

Threads
1,214,642
Messages
6,120,700
Members
448,979
Latest member
DET4492

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