Save File

Papi

Well-known Member
Joined
May 22, 2007
Messages
1,592
I found this on Mr Excel ages ago and have got a lot of mileage from it.

Code:
Sub SaveMe()
With ActiveWorkbook
    .SaveAs Filename:="N:\Drop Box\Pend\" & Format(.Sheets("Sheet1").Range("G8").Value, "") & ".xls", FileFormat:=56
End With
End Sub

What would I need to do for this to take the path from a cell number (Sheet7 cell A20) and leave the file name as is?
 
Thanks again JLGWhiz. It returns a compile error - Invalid or Unqualified Reference on fName = Format(.Sheets at the word .Sheets

Here is the cleaned up version:
Code:
Dim myPath as String, fName As String
myPath = Sheets(7).Range("A20").value
fName = Format(.Sheets("Sheet1").Range("G8").Value, "") & ".xls"
If Right(myPath, 1) <> "\" Then myPath = myPath & "\"
ActiveWorkbook.SaveAs myPath & fName, FileFormat:=56
I moved the Fileformat down to the SaveAs line where it belongs and changed the path reference to sheet 7..
 
Upvote 0

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Thank you Son. It is returning a runtime error 13. I will look that up and see if I can figure it out.

ok, so just use:

Code:
[COLOR=#333333]Activeworkbook.SaveAs Filename:=Worksheets(Sheet1).Range("A1") & "\" & [/COLOR][COLOR=#333333]Worksheets(Sheet1).Range("A1").[/COLOR][COLOR=#333333]Range("A2"), FileFormat:=56
[/COLOR]
 
Upvote 0
oh, I see some typos, so either try this corrected code or try to get message boxes of the values in range A1 and A2, so that you can verify that the input is correct. Finally, if this does not work, try to remove the fileformat = 56

Code:
[COLOR=#333333][COLOR=#333333]Activeworkbook.SaveAs Filename:=Worksheets("Sheet1").Range("A1") & "\" & [/COLOR][/COLOR][COLOR=#333333]Worksheets("Sheet1").[COLOR=#333333][COLOR=#333333][/COLOR][/COLOR][COLOR=#000000]Range("A2"), [/COLOR]FileFormat:=56   [/COLOR]
 
msgbox [COLOR=#333333]Worksheets("Sheet1").Range("A1") 
[/COLOR]msgbox [COLOR=#333333]Worksheets("Sheet1").Range("A2") [/COLOR]
 
Upvote 0
The code shows an error 9 and highlights the entire row yellow and does not make it to the messages. I moved the data to the cells noted just to make sure and tried it with both fileformat:=56 an without but it stops each time.

oh, I see some typos, so either try this corrected code or try to get message boxes of the values in range A1 and A2, so that you can verify that the input is correct. Finally, if this does not work, try to remove the fileformat = 56

Code:
[COLOR=#333333][COLOR=#333333]Activeworkbook.SaveAs Filename:=Worksheets("Sheet1").Range("A1") & "\" & [/COLOR][/COLOR][COLOR=#333333]Worksheets("Sheet1").[COLOR=#333333][COLOR=#333333][/COLOR][/COLOR][COLOR=#000000]Range("A2"), [/COLOR]FileFormat:=56   [/COLOR]
 
msgbox [COLOR=#333333]Worksheets("Sheet1").Range("A1") 
[/COLOR]msgbox [COLOR=#333333]Worksheets("Sheet1").Range("A2") [/COLOR]
 
Upvote 0
ok, so then try to place the save routine after the message boxes and see what happens
 
Upvote 0
The messages show what's in the cells and then it goes to Error 9 and turns the routine yellow.
 
Upvote 0
It just dawned on me that the file name no longer holds the path. I am guessing that I will have to commbine the filename and the path to come together.
 
Upvote 0
when it says error 9, what else does it say?

for example when i tried it, i didn't have a sheet with the name sheet1, so it produced error 9.

also, try this:

create a new workbook, and save it in your documents. Then insert a module and paste:

Code:
Sub TestPath()
Worksheets("Sheet1").Range("A1") = ActiveWorkbook.PathWorksheets("Sheet1").Range("A2") = ActiveWorkbook.Name




ActiveWorkbook.SaveAs Filename:=Worksheets("Sheet1").Range("A1") & "\" & Worksheets("Sheet1").Range("A2")


End Sub
 
Upvote 0

Forum statistics

Threads
1,214,659
Messages
6,120,786
Members
448,992
Latest member
prabhuk279

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