Macro to save file in shared network drive

Dscalf1

New Member
Joined
Jun 14, 2015
Messages
41
I am trying to get this file to be saved in a network drive mapped on my computer. I just want to save it and not close out the file or anything. What I have so far is listed below. I want the file name to be "Bread Reconciliation" + "Whatever date that is listed in cell D1 on Sheet "Bread Input" ". I keep getting this error: Run-time error'1004': Method 'SaveAs' of object'_Workbook' failed

Code:
Private Sub CommandButton1_Click()


Dim FP As String, FN As String
FP = "R:\Manufacturing Transformation\Wrap Reconciliation\Bread Archive\"
FN = Sheets("Bread Input").Range("BD1").Value
ActiveWorkbook.SaveAs Filename:=FP & FN & ".xls"
End Sub
 
Alright, here's what i did. First, just to be clear, you have the workbook you're trying to use this from saved in a .xslm format already, right? If you don't, you can't use macros. I created a new workbook, called my worksheet bread, saved it as an xlsm format, closed it, opened it back up, put bread in BD1, and i made a macro using this code

Code:
Sub Format()
Dim fName As String
fName = Sheets("Bread Input").Range("BD1").Value
ActiveWorkbook.SaveAs Filename:="C:\Users\jdavis\Documents\" & fName & ".xlsm"
End Sub
This code worked perfectly. So if you swap out the file path and have done those steps, the code should work
 
Last edited:
Upvote 0

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Didnt work. So I actually did a record macro and got it to work! However it doesnt add the date to the name everytime it saves so it just saves over the file. This code works and lets me save but any idea on how to add a date to it to get it to save a new file each time?

Code:
Private Sub CommandButton1_Click()
' SaveWorkbook Macro
'
    ChDir "R:\Production\Wrap Reconciliation\Bread Archive"
    ActiveWorkbook.SaveAs Filename:= _
        "R:\Production\Wrap Reconciliation\Bread Archive\Bread Reconciliation v4.xlsm" _
        , FileFormat:=xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False
End Sub
 
Upvote 0
SOLVED:

Code:
Private Sub CommandButton1_Click()' SaveWorkbook Macro


Dim SaveName As String
    SaveName = Sheets("Bread Input").Range("BD1").Text
    ChDir "R:\Production\Wrap Reconciliation\Bread Archive"
    ActiveWorkbook.SaveAs Filename:= _
        "R:\Production\Wrap Reconciliation\Bread Archive\" & SaveName _
        , FileFormat:=xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False
End Sub
 
Upvote 0
looking at your recorded macro it appears that you were not using the right file path before
 
Upvote 0

Forum statistics

Threads
1,224,827
Messages
6,181,195
Members
453,021
Latest member
pingpong7117

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