sanantonio
Board Regular
- Joined
- Oct 26, 2021
- Messages
- 124
- Office Version
- 365
- Platform
- Windows
Hi.
Have a code I've been using for a while. But 2 issues:
It basically copies some data from 1 location to a fresh tab, and then saves that fresh tab as a .csv.
Two parts don't work:
When saving as the same file the "Are you sure as this file already exists" error will still appear.
And
I want to save it as a cell reference, rather than as test.csv
So if cell A1= "=concat("Order Upload ",text(today(),"MMDDYY")"
Then I would want the file to save as A1 rather than test. I've tried
but this doesn't work. Any ideas team?
Have a code I've been using for a while. But 2 issues:
VBA Code:
Sub save()
Application.DisplayAlerts = False
On Error Resume Next
Sheets("CSV").Visible = True
Sheets("CSV").Select
Range("B34").Select
Sheets("Order Upload").Select
Range("Table3[Copy all lines as of A3]").Select
Selection.Copy
Sheets("CSV").Select
Range("A1").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Dim theNewWorkbook As Workbook
Dim currentWorkbook As Workbook
Application.EnableEvents = False
'currentWorkbook is the source workbook, create a new workbook referencing to it with theNewWorkbook
Set currentWorkbook = ActiveWorkbook
Set theNewWorkbook = Workbooks.Add
'do the copy (it's better to check if there is already a 'Worksheet 1' in the new workbook. It it exists delete it or rename it
currentWorkbook.Worksheets("CSV").Copy before:=theNewWorkbook.Sheets(1)
'Remove default sheets in order to have only the copied sheet inside the new workbook
Application.DisplayAlerts = False
Dim i As Integer
For i = theNewWorkbook.Sheets.Count To 2 Step -1
theNewWorkbook.Sheets(i).Delete
Next i
Application.DisplayAlerts = True
'Save File as XLSM
saveLocation = "K:\filepath\test" & ".csv"
theNewWorkbook.SaveAs Filename:=saveLocation, FileFormat:=xlCSV
theNewWorkbook.Close
Sheets("CSV").Visible = False
Sheets("Control").Select
End Sub
It basically copies some data from 1 location to a fresh tab, and then saves that fresh tab as a .csv.
Two parts don't work:
VBA Code:
Application.DisplayAlerts = False
When saving as the same file the "Are you sure as this file already exists" error will still appear.
And
VBA Code:
saveLocation = "K:\filepath\test" & ".csv"
I want to save it as a cell reference, rather than as test.csv
So if cell A1= "=concat("Order Upload ",text(today(),"MMDDYY")"
Then I would want the file to save as A1 rather than test. I've tried
VBA Code:
& Range.("A1")
but this doesn't work. Any ideas team?