+ Reply to Thread
Results 1 to 25 of 25

Run-time error '5': Invalid procedure call or argument

Hybrid View

  1. #1
    Registered User
    Join Date
    12-11-2012
    Location
    Bangalore
    MS-Off Ver
    Excel 2007
    Posts
    20

    Run-time error '5': Invalid procedure call or argument

    Hello everybody,
    this code was working fine on my other system, but when I try to use this on a different system, am getting "Run-time error '5': Invalid procedure call or argument",

    Sub test()
    Dim rng, lr As Long, a, res As String, x As Long
    lr = Cells(Rows.Count, 1).End(xlUp).Row
    rng = Range("a2:b" & lr)
    For x = LBound(rng) To UBound(rng)
    With CreateObject("MSXML2.XMLHTTP")
        .Open "GET", rng(x, 1), False
        .setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
        .send rng(x, 1)
        a = Split(.responsetext, "userbody")(1)
        res = WorksheetFunction.Clean(Left(a, InStr(a, "<!") - 1))
        If InStr(res, "<h5>") Then
            res = Left(res, InStr(res, "<h5>") - 1)
        End If
        rng(x, 2) = Replace(Replace(Replace(Replace(res, Chr(34) & ">", vbNullString), "<br>", Chr(10)), "</h2>", vbNullString), "<h2>", vbNullString)
    End With
    Next
    Range("a2:b" & lr) = rng
    End Sub

    I have colored red where i get this error, any help is greatly appreciated.

    Thanks in Advance

  2. #2
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Am getting error Run-time error '5': Invalid procedure call or argument. please help

    What is the value of rng(x,1) when you get the error?
    The .open method will return the '5' error if, for example, there is nothing in the cell and rng(x,1) evaluates to empty.

    Maybe try changing
    .Open "GET", rng(x, 1), False
    to
    .Open "GET", "http://www.google.com", False
    and see if that works?

  3. #3
    Registered User
    Join Date
    12-11-2012
    Location
    Bangalore
    MS-Off Ver
    Excel 2007
    Posts
    20

    Re: Am getting error Run-time error '5': Invalid procedure call or argument. please help

    Hi Yulugar,

    Thanks for the response, may be I will try it,

  4. #4
    Registered User
    Join Date
    12-11-2012
    Location
    Bangalore
    MS-Off Ver
    Excel 2007
    Posts
    20

    Re: Am getting error Run-time error '5': Invalid procedure call or argument. please help

    Hi Yudlugar,

    am not so good at codes, this code was created for me by Event21 a forum contributor, its actual function was to extract description from craigslist based on the links, I will attach sample of it for your understanding, probably you will get a clear picture about it, please it would be of great help. I just had to enter the links in column 1 and I was able to extract Description on Column 2 from craigslist. If you could create an Excel with the code, it would be of great help. Am absolutely non technical person.

    Thanking you in Advance
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    12-11-2012
    Location
    Bangalore
    MS-Off Ver
    Excel 2007
    Posts
    20

    Re: Am getting error Run-time error '5': Invalid procedure call or argument. please help

    Hi Yudlugar,

    I believe there was a macro enabled button on the sheet, So basically I had to copy the links from the Excel sheet and paste it on this Excel on specific column and then extract the description using the button, its been quite a while I used, there are thousands of these links for which I need to extract the description. Am just stuck. Please help

  6. #6
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Am getting error Run-time error '5': Invalid procedure call or argument. please help

    What happens if you load up internet explorer (or another web browser) and try and access one of the sites in your sample? Try:
    http://miami.craigslist.org/brw/pts/3949953392.html
    I'm thinking that as the code worked on one machine but not when you changed systems that maybe you have restricted web usage or the links are now dead.


    What happens if you run this code:
    Sub test()
    Dim rng, lr As Long, a, res As String, x As Long
    lr = Cells(Rows.Count, 1).End(xlUp).Row
    rng = Range("a2:b" & lr)
    x = LBound(rng)
    With CreateObject("MSXML2.XMLHTTP")
        .Open "GET", rng(x, 1), False
        .setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
        .send rng(x, 1)
        MsgBox .responsetext
    End With
    Range("a2:b" & lr) = rng
    End Sub
    Do you get a messagebox? What does it say?
    Last edited by ragulduy; 07-29-2013 at 10:23 AM.

  7. #7
    Registered User
    Join Date
    12-11-2012
    Location
    Bangalore
    MS-Off Ver
    Excel 2007
    Posts
    20

    Re: Am getting error Run-time error '5': Invalid procedure call or argument. please help

    When I do it manually, am able to do it and all these links are from the past week, all links are live and fine. Am just not able to figure out how I did it last time. I am very sure that it was a button which i used with this code. all I had to do was to copy the links approximately 800 to 1000 links at a time, and then enter the button. It would fetch the description from each link in the next column. Am such numb skull, not able to figure out.

  8. #8
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Am getting error Run-time error '5': Invalid procedure call or argument. please help

    I understand the purpose of the sheet. Again:

    What happens if you load up internet explorer (or another web browser) and try and access one of the sites in your sample? Try:
    http://miami.craigslist.org/brw/pts/3949953392.html

    What happens if you run this code:
    Sub test()
    Dim rng, lr As Long, a, res As String, x As Long
    lr = Cells(Rows.Count, 1).End(xlUp).Row
    rng = Range("a2:b" & lr)
    x = LBound(rng)
    With CreateObject("MSXML2.XMLHTTP")
        .Open "GET", rng(x, 1), False
        .setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
        .send rng(x, 1)
        MsgBox .responsetext
    End With
    Range("a2:b" & lr) = rng
    End Sub
    Do you get a messagebox? What does it say?

  9. #9
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Am getting error Run-time error '5': Invalid procedure call or argument. please help

    Ok, try doing this:
    -open the sample workbook you uploaded.
    -Press Alt+F11
    -Copy and paste this code and then run it (press F5)
    Sub test1()
    Dim rng, lr As Long, a, res As String, x As Long
    lr = Cells(Rows.Count, 1).End(xlUp).Row
    rng = Range("a2:b" & lr)
    x = "http://miami.craigslist.org/brw/pts/3949953392.html"
    With CreateObject("MSXML2.XMLHTTP")
        .Open "GET", rng(x, 1), False
        .setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
        .send rng(x, 1)
        Range("A1") = .responsetext
        End With
    Range("a2:b" & lr) = rng
    End Sub
    What do you get in cell A1 on the worksheet?

  10. #10
    Registered User
    Join Date
    12-11-2012
    Location
    Bangalore
    MS-Off Ver
    Excel 2007
    Posts
    20

    Re: Am getting error Run-time error '5': Invalid procedure call or argument. please help

    This is all I get just as in the image
    Untitled.jpg

  11. #11
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Am getting error Run-time error '5': Invalid procedure call or argument. please help

    That is what you get if you press F5 in the excel sheet so I don't the code has actually ran, try again, I'll try and be more specific with the instructions:
    -Open the sample workbook you gave me:
    -Press Alt+F11 to open the visual basic editor
    -Navigate to where your code is stored
    -Replace it with this code:
    Sub test1()
    Dim rng, lr As Long, a, res As String, x As Long
    lr = Cells(Rows.Count, 1).End(xlUp).Row
    rng = Range("a2:b" & lr)
    x = "http://miami.craigslist.org/brw/pts/3949953392.html"
    With CreateObject("MSXML2.XMLHTTP")
        .Open "GET", rng(x, 1), False
        .setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
        .send rng(x, 1)
        Range("A1") = .responsetext
        End With
    Range("a2:b" & lr) = rng
    End Sub
    -Run the new code, click within the text between "sub" and "end sub" and press F5 or click the run button

    Now do you get something in cell A1?

  12. #12
    Registered User
    Join Date
    12-11-2012
    Location
    Bangalore
    MS-Off Ver
    Excel 2007
    Posts
    20

    Re: Am getting error Run-time error '5': Invalid procedure call or argument. please help

    Its the same thing as in the image I sent you, not able to extract anything.

  13. #13
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Am getting error Run-time error '5': Invalid procedure call or argument. please help

    What happens if you run the macro from the menu rather than using the F5 shortcut?

  14. #14
    Registered User
    Join Date
    12-11-2012
    Location
    Bangalore
    MS-Off Ver
    Excel 2007
    Posts
    20

    Re: Am getting error Run-time error '5': Invalid procedure call or argument. please help

    runtime error 13, type mismatch

  15. #15
    Registered User
    Join Date
    12-11-2012
    Location
    Bangalore
    MS-Off Ver
    Excel 2007
    Posts
    20

    Re: Am getting error Run-time error '5': Invalid procedure call or argument. please help

    If you see in my previous post when I got this code, i had even attached the sample file and the contributor wrote this code for me, the link is http://www.excelforum.com/excel-prog...47#post3048047

  16. #16
    Registered User
    Join Date
    12-11-2012
    Location
    Bangalore
    MS-Off Ver
    Excel 2007
    Posts
    20

    Re: Am getting error Run-time error '5': Invalid procedure call or argument. please help

    Hello Yudlugar,

    If I gave you a sample will you be able to write new code, it would be of great help. I use excel 2007

  17. #17
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Am getting error Run-time error '5': Invalid procedure call or argument. please help

    what about if you try and run this code:
    Sub test1()
    Dim x
    x = "http://miami.craigslist.org/brw/pts/3949953392.html"
    With CreateObject("MSXML2.XMLHTTP")
        .Open "GET", x, False
        .setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
        .send x
        MsgBox .responsetext
    End With
    End Sub

  18. #18
    Registered User
    Join Date
    12-11-2012
    Location
    Bangalore
    MS-Off Ver
    Excel 2007
    Posts
    20

    Re: Am getting error Run-time error '5': Invalid procedure call or argument. please help

    I got a new pop up, image attached below
    NewImage.jpg

  19. #19
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Am getting error Run-time error '5': Invalid procedure call or argument. please help

    I don't think there is a problem with the code, looks like it works ok to me.

    I'm trying to determine what response you get to the msxml2.xmlhttp request to see if I can determine what the problem is.

  20. #20
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Am getting error Run-time error '5': Invalid procedure call or argument. please help

    End of the day so I've tried to come up with another method that might work:
    Option Explicit
    
    Sub test()
    Dim rng, lr As Long, a, res As String, x As Long
    On Error GoTo not_found
    lr = Cells(Rows.Count, 1).End(xlUp).Row
    rng = Range("a2:b" & lr)
    For x = LBound(rng) To UBound(rng)
    With CreateObject("MSXML2.XMLHTTP")
        .Open "GET", rng(x, 1), False
        .setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
        .send rng(x, 1)
        a = .responsetext
        
        a = Range("A23")
        
        a = Strings.Left(a, InStr(1, a, "<section class=""cltags"""))
        a = Strings.Right(a, Len(a) - InStr(1, a, "<section id=""postingbody"">") - 25)
        a = Replace(a, "<br>", "")
        a = Replace(a, "</section>", "")
        a = Replace(a, "<", "")
        rng(x, 2) = a
    End With
    next_for_loop:
    Next
    Range("a2:b" & lr) = rng
    On Error GoTo 0
    Exit Sub
    not_found:
    rng(x, 2) = "DESCRIPTION NOT FOUND"
    Resume next_for_loop
    End Sub

  21. #21
    Registered User
    Join Date
    12-11-2012
    Location
    Bangalore
    MS-Off Ver
    Excel 2007
    Posts
    20

    Re: Run-time error '5': Invalid procedure call or argument

    All the samples are which I showed you, comes up with a result "DESCRIPTION NOT FOUND", I think it works but its not extracting the data, the whole list is "DESCRIPTION NOT FOUND"

  22. #22
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Run-time error '5': Invalid procedure call or argument

    Ok good, sorry this is a bit of a pain, trying to debug remotely isn't fun.

    What does this code give you:
    Sub test1()
    Dim x
    x = "http://miami.craigslist.org/brw/pts/3949953392.html"
    With CreateObject("MSXML2.XMLHTTP")
        .Open "GET", x, False
        .setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
        .send x
        MsgBox Split(.responsetext, "userbody")(1)
    End With
    End Sub

  23. #23
    Registered User
    Join Date
    12-11-2012
    Location
    Bangalore
    MS-Off Ver
    Excel 2007
    Posts
    20

    Re: Run-time error '5': Invalid procedure call or argument

    Yudlugar, I think something is happening, it is extracting now, but kind of weird am attaching the sample file along, I just want the description from each link, I think it is doing but something is wrong please take a look at the attachment. Its kind of extracting html, scripts etc

    Thanks
    Attached Files Attached Files

  24. #24
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Run-time error '5': Invalid procedure call or argument

    Sorry, I forgot to take out a bit I included while testing, try this:
    Sub test()
    Dim rng, lr As Long, a, res As String, x As Long
    On Error GoTo not_found
    lr = Cells(Rows.count, 1).End(xlUp).Row
    rng = Range("a2:b" & lr)
    For x = LBound(rng) To UBound(rng)
    With CreateObject("MSXML2.XMLHTTP")
        .Open "GET", rng(x, 1), False
        .setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
        .send rng(x, 1)
        a = .responsetext
        a = Strings.Left(a, InStr(1, a, "<section class=""cltags"""))
        a = Strings.Right(a, Len(a) - InStr(1, a, "<section id=""postingbody"">") - 25)
        a = Replace(a, "<br>", "")
        a = Replace(a, "</section>", "")
        a = Replace(a, "<", "")
        rng(x, 2) = a
    End With
    next_for_loop:
    Next
    Range("a2:b" & lr) = rng
    On Error GoTo 0
    Exit Sub
    not_found:
    rng(x, 2) = "DESCRIPTION NOT FOUND"
    Resume next_for_loop
    End Sub

  25. #25
    Registered User
    Join Date
    12-11-2012
    Location
    Bangalore
    MS-Off Ver
    Excel 2007
    Posts
    20

    Re: Run-time error '5': Invalid procedure call or argument

    Wow Yudlugar,

    It worked, and it works better than before, I don't know what you did, but its awesome. Thanks a Million for this Yudlugar.

    Regards
    Bruce

+ 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. 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
  2. Macro Error - Invalid Procedure Call or Argument
    By mcordi in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-12-2011, 05:40 PM
  3. Invalid procedure call or argument error
    By Patrick Simonds in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-12-2006, 06:45 PM
  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

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