Save file without prompting in Excel Macro

W

wildatom

I'm trying to save the file name of the imported CSV with the name of
cell at A1. No matter what I do it keeps
prompting me for a file name, however the prompt correctly displays the
name in cell A1.

Since I want to automate this macro I
don't want to be prompted at all.

Main Document = Master.xls
Imports = data.csv
Save as = whatever text is in A1 without prompting me in the same
directory
Close excel

Range("A1").Select
Application.DisplayAlerts = False
FName = Application.GetSaveAsFilename(Sheets("data").Range("A1").Value,
fileFilter:="CSV Files (*.csv), *.csv")
Application.DisplayAlerts = True
ActiveWindow.Close
End Sub
 
W

wildatom

Figured it out..

Range("A1").Select
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs _
Filename:=(Sheets("data").Range("A1").Value), _
FileFormat:=xlCSV, CreateBackup:=False
Application.DisplayAlerts = False
ActiveWindow.Close
 
R

Ron de Bruin

GetSaveAsFilename not save the file it only let you enter the file name.

You must copy the sheet to a new workbook and save that workbook with the value of A1

Try this for the activesheet

Sub ActiveSheet_CSV_File()
Dim wb As Workbook
Dim Fname As String
Fname = ThisWorkbook.Path & "\" & Range("A1").Value & ".csv"
Application.ScreenUpdating = False
ActiveSheet.Copy
Set wb = ActiveWorkbook
With wb
.SaveAs Fname, FileFormat:=xlCSV
.Close False
End With
Application.ScreenUpdating = True
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top