Addition to existing macro - to save sheet as CSV

Kickingkangaroos

New Member
Joined
Sep 2, 2009
Messages
46
Hi All,

I have written a very simple macro, to perform a couple of simple actions to tidy up a sheet, which I have to run each day:

Code:
Sub SamplesUpload()
'
' SamplesUpload Macro
'
'
    Range("A:A,G:G").Select
    Range("G1").Activate
    Selection.Delete Shift:=xlToLeft
    Rows("1:8").Select
    Selection.Delete Shift:=xlUp
    Range("A1").Select
    Application.Run "PERSONAL.xlsm!CSV"
End Sub

The "PERSONAL.xlsm!CSV" is another small macro which wraps quote marks ("") around the content of each populated cell in Column B.

What I am trying to do - is add a small amount of code to this above macro, which automatically saves the worksheet as a CSV file, with the file name as the current date; ideally in the standard format dd-mm-yyyy - but I'm not fussy if that is particularly complex. (EDIT: Please can you confirm how I would save this to C:\Samples Upload\ many thanks.

I understand that it is not particularly long-winded to do Save As --> CSV and type in the date - but this has to be done every day, so if it can be avoided by a simple amount of code, it would be great.

Any help would be greatly appreciated - please let me know if you need any further information.

Many thanks,

Andy
 
Last edited:

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Hi again All,

I'm posting myself a reply (sad I know!) - as I managed to cobble together bits of code from various people (and add a tiny bit myself), to sort this out.

So first off - thank you very much to all the people who have posted on here, whose work I have shamelessly "borrowed" to piece together in order to get what I need - the code I ended up using is as follows:

Code:
Sub SaveAsCSV()
Dim DTAddress As String
Dim FileName As String
Dim FullyQualifiedFileName As String
'Get the path to the User's Desktop
DTAddress = "C:\Samples Upload\"
'Build the Workbook name to save as CSV format File
FileName = ActiveWorkbook.Name
FileName = Left(FileName, InStr(FileName, ".")) & "csv"
'Build the fully-qualified Workbook "save" path
FullyQualifiedFileName = DTAddress & FileName
'Switch Off all Application alerts before saving (in case the file already exists etc.)
Application.DisplayAlerts = False
'Save the current active sheet as a CSV file to the user's Desktop
ActiveWorkbook.SaveAs FileName:=FullyQualifiedFileName, FileFormat:=xlCSV

'Close the original Workbook without saving changes
ThisWorkbook.Close savechanges:=False
'Switch all Application alerts back on before exiting
Application.DisplayAlerts = True
End Sub

As the workbook (and worksheet) name was always going to be the current date - I was able to reference that to get the CSV file name.

Cheers,

Andy
 
Upvote 0

Forum statistics

Threads
1,224,616
Messages
6,179,911
Members
452,949
Latest member
beartooth91

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