Save As Macro Button - with special name

edwardzbrown

New Member
Joined
Jun 12, 2017
Messages
20
I know this question has been answered before but I can't get it to work. I've seen it done a couple different ways and I try them all but I keep getting an error. I want a button that creates a relative path copy of my excel document and uses the values of two different cells as the file name. Value #1 is the last date of data entry. I have a cell with a formula that pulls the latest value in a column (is there any problem with using a cell that has a formula?). Value #2 is the name of the project. So the new file would be named date and project name. I actually want a #3rd value and that would just be the word "report". This is a tool we will send to our partners and they'll fill it out. That's why a static path can't work. It'll be used on all different computers. For simplicity sake it just needs to save someplace it can be found. The same folder the file is originally opened from is just fine. (I even seen a fancy 'IF-statement in case the file were opened from the internet and there is no relative path. A message box prompts the user to save first then generate a report.)

I'm not sure what I'm doing wrong. I never get it to even save. The following is the best example of what I'm trying to do that I've found. Thank you for all your help.

Sub Saving()

Dim part1 As String
Dim part2 As String

part1 = Range("C5").Value
part2 = Range("C8").Value

ActiveWorkbook.SaveAs Filename:= _

"C:\-docs\cmat\Desktop\pieteikumi" & part1 & " " & part2 & ".xlsm", FileFormat:= _
xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False

End Sub
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Try this :
Code:
Sub Saving()


Dim part1 As String
Dim part2 As String


part1 = Month([C5]) & "-" & Day([C5]) & "-" & Year([C5])
part2 = Range("C8").Value


ActiveWorkbook.SaveAs Filename:= _
"C:\-docs\cmat\Desktop\pieteikumi " & part1 & " " & part2 & " Report.xlsm", FileFormat:= _
xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False


End Sub
 
Last edited:
Upvote 0
That worked. Thank you! This is the full thing I used. I have a few extras to help my sheet work:

Sub Button9_Click()
'Add Entry Field A1010
ActiveWorkbook.RefreshAll 'so refreshing




'unlock sheet
ActiveSheet.Unprotect ("password")


'save as code
Dim part1 As String
Dim part2 As String

part1 = Month(['Revision History'!A2]) & "-" & Day(['Revision History'!A2]) & "-" & Year(['Revision History'!A2])
part2 = Range("Dashboard!A5").Value

ActiveWorkbook.SaveAs Filename:=relativePath & part1 & " " & part2 & " Report.xlsm", FileFormat:= _
xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False




MsgBox "Report Created", vbInformation, "A-SCR2"


'lock sheet
ActiveSheet.Protect ("password"), DrawingObjects:=True, Contents:=True, Scenarios:=True _
, AllowFormattingRows:=True, AllowInsertingColumns:=True, AllowInsertingRows:=True, _
AllowInsertingHyperlinks:=True, AllowDeletingColumns:=True, _
AllowDeletingRows:=True
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,812
Messages
6,121,696
Members
449,048
Latest member
81jamesacct

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