+ Reply to Thread
Results 1 to 5 of 5

Runtime Error 5: Invalid procedure call or argument

Hybrid View

  1. #1
    Registered User
    Join Date
    06-30-2009
    Location
    Chennai, India
    MS-Off Ver
    Excel 2003
    Posts
    3

    Runtime Error 5: Invalid procedure call or argument

    Hi all,
    I am trying to extract the texts from a web page and write it to a text file.
    I am able to read the text by using internetexplorer.application but when I try to write it to the notepad sometimes it gives Runtime Error 5: Invalid procedure call or argument.
    Microsoft VB Help says that it happens bcoz of "An argument probably exceeds the range of permitted values."

    Can someone help me to get rid of this problem.

    Thanks in advance.

    -Arasi

  2. #2
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,332

    Re: Runtime Error 5: Invalid procedure call or argument

    Not without seeing the code...
    Everyone who confuses correlation and causation ends up dead.

  3. #3
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,332

    Re: Runtime Error 5: Invalid procedure call or argument

    Which line gives the error?

  4. #4
    Registered User
    Join Date
    06-30-2009
    Location
    Chennai, India
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: Runtime Error 5: Invalid procedure call or argument

    Sub GetTextFromIe()
    
    Dim NPOFile$, myFile$
    Dim ie As Object, objDoc As Object, f As Object, fs As Object
    Dim strURI As String
    
    strURI = "www.google.com"
    
    Set ie = CreateObject("internetexplorer.application")
    ie.Navigate strURI
    
    'Wait for page to load!
    Do
    If ie.ReadyState = 4 Then
    ie.Visible = False
    Exit Do
    Else
    DoEvents
    End If
    Loop
    
    Set objDoc = ie.Document
    
    strMyPage = objDoc.body.innerText
    
    
    'Use this Text file!
    
    Dim FileSave
    FileSave = Application.GetSaveAsFilename("Contents-" & Format(Date, "dd-mm-yy") & "-" & Format(Time, "hh") & "-" & Format(Time, "nn") & "-" & Format(Time, "ss"), "Text Files (*.txt),*.txt")
    Set fs = CreateObject("Scripting.FileSystemObject")
    Set f = fs.CreateTextFile(FileSave, True)
    myFile = FileSave
    
    NPOFile = "NotePad.exe " & myFile
    
    'Work with file [Append Text to File].
    f.Write (strMyPage)
    f.Close
    
    'Open NotePad with a data file!
    ActiveSheet.Select
    
    Call Shell(NPOFile, 1)
    
    Set objDoc = Nothing
    Set ie = Nothing
    End Sub


    The line f.Write (strMyPage) gives me the error.

  5. #5
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,332

    Re: Runtime Error 5: Invalid procedure call or argument

    There's a character in there that Write doesn't like. Try this instead:
    f.Write Replace$(strmypage, ChrW(9660), "")

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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