This is a very good vba code to build folders and save stuff. I use it all the time, but I want to use this code on a click of a button to save it to a folder I prefer without using --> SaveName = Trim(InputBox("Enter the file name you want to save. (blank to skip)", "Input required."))
What do I need to remove or add to this code below for that to work thanks.
So basically I need to remove that and have an area in code to name sheet and just save it to a folder I name. While using this code without the Input required box. Thanks.
Sub SaveFileButton()
Dim SaveName As String
Const MyPath As String = "C:\Test\" 'This is the path it's using for saves before the dates
ReName:
On Error GoTo ErrorHandle
SaveName = Trim(InputBox("Enter the file name you want to save. (blank to skip)", "Input required."))
If Len(SaveName) > 0 Then
SaveName = SaveName & ".xlsx"
If Len(Dir(MyPath & Format(Now, "yy") & "-" & Format$(Now, "mmm"), vbDirectory)) = 0 Then
MkDir MyPath & Format(Now, "yy") & "-" & Format$(Now, "mmm") & "\"
End If
If Len(Dir(MyPath & Format(Now, "yy") & "-" & Format$(Now, "mmm") & "\" & Format(Now, "mm") & "-" & Format(Now, "dd") & "-" & Format(Now, "yyyy"), vbDirectory)) = 0 Then
MkDir MyPath & Format(Now, "yy") & "-" & Format$(Now, "mmm") & "\" & Format(Now, "mm") & "-" & Format(Now, "dd") & "-" & Format(Now, "yyyy") & "\"
End If
ActiveWorkbook.SaveAs Filename:=MyPath & Format(Now, "yy") & "-" & Format$(Now, "mmm") & "\" & Format(Now, "mm") & _
"-" & Format(Now, "dd") & "-" & Format(Now, "yyyy") & "\" & SaveName, FileFormat:=xlOpenXMLWorkbook
End If
Exit Sub
ErrorHandle:
If Err.Number = 75 Then
Resume Next
ElseIf Err.Number = 1004 Then
MsgBox ("That name is already used for this day. Please try again!")
GoTo ReName
Else: MsgBox ("There is an unknown error")
End If
End Sub
What do I need to remove or add to this code below for that to work thanks.
So basically I need to remove that and have an area in code to name sheet and just save it to a folder I name. While using this code without the Input required box. Thanks.
Sub SaveFileButton()
Dim SaveName As String
Const MyPath As String = "C:\Test\" 'This is the path it's using for saves before the dates
ReName:
On Error GoTo ErrorHandle
SaveName = Trim(InputBox("Enter the file name you want to save. (blank to skip)", "Input required."))
If Len(SaveName) > 0 Then
SaveName = SaveName & ".xlsx"
If Len(Dir(MyPath & Format(Now, "yy") & "-" & Format$(Now, "mmm"), vbDirectory)) = 0 Then
MkDir MyPath & Format(Now, "yy") & "-" & Format$(Now, "mmm") & "\"
End If
If Len(Dir(MyPath & Format(Now, "yy") & "-" & Format$(Now, "mmm") & "\" & Format(Now, "mm") & "-" & Format(Now, "dd") & "-" & Format(Now, "yyyy"), vbDirectory)) = 0 Then
MkDir MyPath & Format(Now, "yy") & "-" & Format$(Now, "mmm") & "\" & Format(Now, "mm") & "-" & Format(Now, "dd") & "-" & Format(Now, "yyyy") & "\"
End If
ActiveWorkbook.SaveAs Filename:=MyPath & Format(Now, "yy") & "-" & Format$(Now, "mmm") & "\" & Format(Now, "mm") & _
"-" & Format(Now, "dd") & "-" & Format(Now, "yyyy") & "\" & SaveName, FileFormat:=xlOpenXMLWorkbook
End If
Exit Sub
ErrorHandle:
If Err.Number = 75 Then
Resume Next
ElseIf Err.Number = 1004 Then
MsgBox ("That name is already used for this day. Please try again!")
GoTo ReName
Else: MsgBox ("There is an unknown error")
End If
End Sub