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

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
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,223,908
Messages
6,175,304
Members
452,633
Latest member
DougMo

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