I am trying to save a new opened workbook as a csv on a Mac but keep running into error 1004: application or object defined error
here is the code:
I've tried Application.ThisWorkbook.SaveAs, ThisWorkbook.Sheets("Sheet1").SaveAs, ActiveWorkbook.ActiveSheet.SaveAs, ActiveWorkbook.Sheets("Sheet1").SaveAs, and ActiveWorkbook.SaveAs and all fail. office version is 365.
When I record a macro to do the same thing the code is like what I already tried:
here is the code:
VBA Code:
Dim directory As String
directory = "/Users/johnsmith/Desktop"
Dim mystring, clientname
mystring = Range("B2").Text
clientname = Mid(mystring, WorksheetFunction.Find("#", WorksheetFunction.Substitute(mystring, "/", "#", 3)) + 1, WorksheetFunction.Find("#", WorksheetFunction.Substitute(mystring, "/", "#", 4)) - WorksheetFunction.Find("#", WorksheetFunction.Substitute(mystring, "/", "#", 3)) - 1)
Dim wbname As String
wbname = WorksheetFunction.Substitute(Date, "/", ".") & " (" & clientname & ") " & "Upload"
Workbooks.Add
ChDir directory
ThisWorkbook.ActiveSheet.SaveAs Filename:=directory & "/" & wbname & ".csv", _
FileFormat:=xlCSVUTF8, CreateBackup:=False
I've tried Application.ThisWorkbook.SaveAs, ThisWorkbook.Sheets("Sheet1").SaveAs, ActiveWorkbook.ActiveSheet.SaveAs, ActiveWorkbook.Sheets("Sheet1").SaveAs, and ActiveWorkbook.SaveAs and all fail. office version is 365.
When I record a macro to do the same thing the code is like what I already tried:
VBA Code:
Workbooks.Add
ChDir "/Users/johnsmith/Desktop/"
ActiveWorkbook.SaveAs FileName:="/Users/cameronspiller/Desktop/Book2.csv", _
FileFormat:=xlCSVUTF8, CreateBackup:=False