Hello,
I'm trying to save a newly created file in csv format.
I am copying results from one open file, and pasting in a new workbook, and then trying to save the new workbook as a csv file.
My code is below. See the "Save File as CSV" section below. Thanks!
I'm trying to save a newly created file in csv format.
I am copying results from one open file, and pasting in a new workbook, and then trying to save the new workbook as a csv file.
My code is below. See the "Save File as CSV" section below. Thanks!
Code:
[SIZE=2]Sub Monthly_Device_Volume_Map()
'
' Monthly_Device_Volume_Map Macro
'
Sheets("Device_volume_map").Select
Range("A2").Select
Selection.ListObject.QueryTable.Refresh BackgroundQuery:=False
Sheets("Device_volume_map").Select
Columns("A:B").Select
Selection.Copy
Sheets("Verix Upload").Select
Columns("A:B").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("A1").Select
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = "Material"
Range("B1").Select
ActiveCell.FormulaR1C1 = "Method"
Columns("B:B").Select
Selection.Replace What:="1", Replacement:="QTY", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Range("A1").Select
Sheets("Verix Upload").Select
Application.CutCopyMode = False
Sheets("Verix Upload").Copy
Application.DisplayAlerts = False
' Check for year folder and create if needed
If Len(Dir("Z:\BM 1 - Verix Data and Upload Management\Device Volume Map" & Year(Date), vbDirectory)) = 0 Then
MkDir "Z:\BM 1 - Verix Data and Upload Management\Device Volume Map" & Year(Date)
End If
' Check for month folder and create if needed
If Len(Dir("Z:\BM 1 - Verix Data and Upload Management\Device Volume Map" & Year(Date) & "\" & MonthName(Month(Date), False), vbDirectory)) = 0 Then
MkDir "Z:\BM 1 - Verix Data and Upload Management\Device Volume Map" & Year(Date) & "\" & MonthName(Month(Date), False)
End If
[FONT=microsoft sans serif][I][U][B]The next part is giving me the run-time error:[/B][/U][/I][/FONT]
'Save File as CSV
ActiveWorkbook.SaveAs Filename:= _
"Z:\BM 1 - Verix Data and Upload Management\Device Volume Map" & Year(Date) & "\" & MonthName(Month(Date), False) & "\" & Format(Now(), "MM.DD.YYYY") & "\" & "Device_volume_map.csv" _
, FileFormat:=xlCSV, CreateBackup:=False
'Allows Popup Message below
Application.DisplayAlerts = True
'Popup Message
MsgBox "File Saved As:" & vbNewLine & "Z:\BM 1 - Verix Data and Upload Management\Device Volume Map" & Year(Date) & "\" & MonthName(Month(Date), False) & "\" & Format(Now(), "MM.DD.YYYY") & "\" & "Device_volume_map.csv"
'Closes the standalone CSV file created above
Windows("Device_Volume_Map.csv").Activate
ActiveWindow.Close
'Tells Excel to close excel 2010 after file is saved
Application.Quit
'Saves this workbook with changes
ActiveWindow.Close SaveChanges:=True
End Sub[/SIZE]
Last edited by a moderator: