+ Reply to Thread
Results 1 to 2 of 2

Help! Run-Time Error '5': Invalid procedure call or argument

  1. #1
    Registered User
    Join Date
    09-19-2014
    Location
    richmond,canada
    MS-Off Ver
    2010
    Posts
    6

    Exclamation Help! Run-Time Error '5': Invalid procedure call or argument

    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

  2. #2
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,525

    Re: Help! Run-Time Error '5': Invalid procedure call or argument

    Check this out for looping through a folder
    http://www.xlorate.com/vba-examples....rough%20Folder

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Run-time error 5, Invalid procedure call or argument
    By cmb80 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-23-2014, 08:29 AM
  2. Run-time error '5': Invalid procedure call or argument
    By mcbruce76 in forum Excel Programming / VBA / Macros
    Replies: 24
    Last Post: 07-30-2013, 08:31 PM
  3. Macro Run Time error - Invalid procedure call or argument
    By clundeen in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-01-2011, 01:59 AM
  4. [SOLVED] Run-time error '5': Invalid Procedure Call or Argument
    By Nikila in forum Excel General
    Replies: 2
    Last Post: 02-24-2006, 05:30 PM
  5. Run Time Error 5 - Invalid Procedure Call or Argument Q
    By John in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-26-2005, 05:05 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1