Hello,
I am recieving a "Run-Time error '5': Invalid procedure call or argument" when I try to run the following code. It suppose to export each row into a html file and use the "C" column as the files' names.
The funny part is the error only show up on my computer and the code works fine on other computers.
Can anyone help?
Thanks a lot.
Sub SaveAs_HTML()
Const ForReading = 1, ForWriting = 2, ForAppending = 3
Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0
Dim fs, f, ts, s
Dim WS_Src As Worksheet, Rng As Range, c As Range, d As Range
Dim Folder As String
Folder = "C:\SaveEachLine\"
Set WS_Src = ThisWorkbook.Worksheets("Data")
Set Rng = WS_Src.Range("C1", WS_Src.Range("C" & Rows.Count).End(xlUp))
For Each c In Rng
Set fs = CreateObject("Scripting.FileSystemObject")
fs.CreateTextFile Folder & c.Value & ".html"
Set f = fs.GetFile(Folder & c.Value & ".html")
Set ts = f.OpenAsTextStream(ForWriting, TristateUseDefault)
For Each d In Intersect(c.EntireRow, WS_Src.UsedRange)
ts.write d.Value & Chr(9)
Next
ts.Close
Next
End Sub
Bookmarks