Run-Time error '1004' Method 'SaveAs' of object'_Wokkbook' failed

Bmath81

New Member
Joined
Nov 6, 2019
Messages
6
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!


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:
No, it won't create a folder, you will have to do that in much the same way as you did for the other folders.
 
Upvote 0

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.

Forum statistics

Threads
1,224,818
Messages
6,181,151
Members
453,021
Latest member
Justyna P

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