Reputation: 7107
So I have tried a few placement issues and I cant seem to figure out why this works in some of my macros but not my current one? Any pointers?
Private Sub CommandButton1_Click()
Dim filelocation1 As String
Dim wbO As Workbook
Dim wsO as Worksheet
filelocation1 = "C:\Users\Ashleysaurus\Desktop\doug" & "\" & Now() & ".xls"
Set wbO = Workbooks.Add
With wbO
Set wsO = wbO.Sheets("Sheet1")
wbO.SaveAs Filename:=filelocation1, FileFormat:=56
Upvotes: 0
Views: 59
Reputation:
You cannot use / in a filename
"C:\Users\Ashleysaurus\Desktop\doug" & "\" & Now() & ".xls"
returns: "C:\Users\Ashleysaurus\Desktop\doug\6/26/2016 11:15:54 PM.xls"
Use:
"C:\Users\Ashleysaurus\Desktop\doug" & "\" & Format(Now, "yyyy-mm-dd hh-mm") & ".xls"
returns: "C:\Users\Ashleysaurus\Desktop\doug\2016-06-26 23-15.xls"
Private Sub CommandButton1_Click() Dim filelocation1 As String Dim wbO As Workbook Dim wsO As Worksheet filelocation1 = "C:\Users\Ashleysaurus\Desktop\doug" & "\" & Format(Now, "yyyy-mm-dd hh-mm") & ".xls" Set wbO = Workbooks.Add With wbO Set wsO = wbO.Sheets("Sheet1") wbO.SaveAs Filename:=filelocation1, FileFormat:=56 End With End Sub
Upvotes: 1