0

Whenever I try to run code that I found online that apparently do this I get a error message.

Run-time error '-2147418113 (8000ffff)' Automation error Catastrophic failure

I've tried some modifications but I cant make it work, I've attached the unedited code I've been trying to make work. Any help would be greatly appriciated.

Public Sub SaveWorksheetsAsCsv()
Dim WS As Excel.Worksheet
Dim SaveToDirectory As String

    SaveToDirectory = "C:\Users\Name\OneDrive\Documents\test"

    For Each WS In ThisWorkbook.Worksheets
        WS.SaveAs SaveToDirectory & WS.Name, xlCSV
    Next

End Sub
FunThomas
  • 23,043
  • 3
  • 18
  • 34
Nrhoodie
  • 5
  • 2
  • Don't know if this causing the catastophic failure, but you are missing a path separator (Backslash) between the path and the filename. Also, if your worksheet contains characters that are not allowed in a file name, the code will fail, see https://stackoverflow.com/q/1976007/7599798 – FunThomas Aug 24 '23 at 11:53
  • 1
    Does the Worksheet Name contain Characters that are Forbidden in Filenames, such as `\​`, `/`, `:`, `*`, `?`, `"`, `<`, `>`, or `|`? – Chronocidal Aug 24 '23 at 12:02
  • Did you change `C:\Users\Name` into your actual name (or at least, an existing path)? – Paul Aug 24 '23 at 12:41

0 Answers0