+ Reply to Thread
Results 1 to 15 of 15

Run Time Error '13' Type Mismatch

  1. #1
    Forum Contributor
    Join Date
    06-20-2011
    Location
    Auckland, NZ
    MS-Off Ver
    Excel 2013
    Posts
    165

    Thumbs up Run Time Error '13' Type Mismatch

    Hi guys,

    I am trying to browse a file and then download a file into the selected browsed file location.

    here is my code

    Please Login or Register  to view this content.
    I am getting a mismatch error here in this particular set of code:
    MsgBox "Download Status : " & URLDownloadToFile(0, URL, LocalFilename, 0, 0) = 0

    thanks guys..

    Best Regards
    Plasma33
    Last edited by plasma33; 12-24-2014 at 09:38 PM.

  2. #2
    Valued Forum Contributor
    Join Date
    06-19-2010
    Location
    Holywell, N Wales, UK
    MS-Off Ver
    Excel 2013
    Posts
    470

    Re: Run Time Error '13' Type Mismatch

    Hello Plasma33

    Try:

    Please Login or Register  to view this content.
    To convert the Boolean function call 'result' to String
    If this was helpful then please click the small star icon at the bottom left of my post. A little appreciation goes a long way.

  3. #3
    Forum Expert Tinbendr's Avatar
    Join Date
    06-26-2012
    Location
    USA
    MS-Off Ver
    Office 2010
    Posts
    2,125

    Re: Run Time Error '13' Type Mismatch

    Barryleajo beat me to it.
    David
    (*) Reputation points appreciated.

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Run Time Error '13' Type Mismatch

    You shouldn't need to convert the boolean to a string.

    Have you checked what this is returning when you get the error?
    Please Login or Register  to view this content.
    If posting code please use code tags, see here.

  5. #5
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Run Time Error '13' Type Mismatch

    Norie,

    I get the same 'Error 13'. A long value of 0 is returned. When the '= 0' is removed the function works fine. I get the same error even when I cast everything to long using CLng.

    ---------------------

    However, since 'Option Explicit' is not used at the top, incorrect API declarations sneak by the compiler.
    Try the following code. After testing, remove the lines in red below, which were used to test a smaller file to download.
    Please Login or Register  to view this content.
    To prevent typos from ruining days and weeks of work 'Option Explicit' is NEEDED at the top of each code module. This prevents errors caused by missspellings and FORCES every variable to be DECLARED (e.g. dim i as Integer). http://www.cpearson.com/excel/DeclaringVariables.aspx

    Lewis
    Last edited by LJMetzger; 12-24-2014 at 11:15 AM.

  6. #6
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Run Time Error '13' Type Mismatch

    I think wrapping the expression in quotes might fix things.
    Please Login or Register  to view this content.
    If you don't do that you could have something like this,
    Please Login or Register  to view this content.
    which will return a type mismatch.

    As will this,
    Please Login or Register  to view this content.
    and this.
    Please Login or Register  to view this content.
    All work without error when you wrap the expression in ().
    Please Login or Register  to view this content.

  7. #7
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Run Time Error '13' Type Mismatch

    Norie,

    Wrapping the expression in parentheses made runtime error 13 go away. Great catch.
    Please Login or Register  to view this content.
    Lewis

  8. #8
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Run Time Error '13' Type Mismatch

    Oops, meant quotes not brackets.

  9. #9
    Forum Contributor
    Join Date
    06-20-2011
    Location
    Auckland, NZ
    MS-Off Ver
    Excel 2013
    Posts
    165

    Re: Run Time Error '13' Type Mismatch

    Hi guys,

    First of all Wish everyone of you a Merry Christmas!!

    Thank you all for your kind replies. I checked all the solutions given by you guys. It all worked but its giving me a message saying "Download Status: False". I checked the link and its working perfectly. So the URL is not an issue. I also disabled my antivirus and then tried again but I am still getting the same message.

    The code that I am using now is as following:
    Please Login or Register  to view this content.
    @Lewis,
    I tried your solution but its giving me a type mismatch compile error in the following piece of code highlighting "URLDownloadToFile":
    Please Login or Register  to view this content.
    Thanks guys for all your help!!

    Best Regards
    Plasma33
    Last edited by plasma33; 12-24-2014 at 07:45 PM. Reason: Forgot to Wish everyone Merry Christmas!!

  10. #10
    Forum Contributor
    Join Date
    06-20-2011
    Location
    Auckland, NZ
    MS-Off Ver
    Excel 2013
    Posts
    165

    Re: Run Time Error '13' Type Mismatch

    @Norie,
    When I tried your piece of code which is
    Please Login or Register  to view this content.
    ...I got the following message i.e. "Download Status: -2146697203". I tried searching that number on google but didn't find anything.

    Thanks.

    Best Regards
    Plasma33

  11. #11
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Run Time Error '13' Type Mismatch

    plasma,

    Your error is probably because the file can't be found.

    Your original code:
    Please Login or Register  to view this content.

    Corrected code (tested and working):
    Please Login or Register  to view this content.

    Lewis

  12. #12
    Forum Contributor
    Join Date
    06-20-2011
    Location
    Auckland, NZ
    MS-Off Ver
    Excel 2013
    Posts
    165

    Re: Run Time Error '13' Type Mismatch

    hi lewis,

    thank you for the prompt reply. it works perfectly fine now. i just have one more query. now the file thats downloading has file name as "whatever_file_chosen_by_user.exef1040sb.pdf". i just want the file name as "f104sb.pdf" but the file should be downloaded in the same location as the browsed file.

    thanks lewis for all your help.

    best regards
    plasma33

  13. #13
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Run Time Error '13' Type Mismatch

    plasma33

    Eh, I didn't post that code.
    Last edited by Norie; 12-25-2014 at 08:41 AM.

  14. #14
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Run Time Error '13' Type Mismatch

    Hi plasma33,

    The rep points are much appreciated.

    1. I changed the code to look for a folder instead of a file.
    2. Your profile says Excel 2003, but the code does not compile using Excel 2003. Please update your profile to indicate which version(s) of Excel you are using.
    3. I corrected the declarations at the top to eliminate sleep(), which is not needed. I added URLDownloadToFile() declaration at the top so the code should compile for any version of Excel.
    4. You should use 'Option Explicit' at the very top of your file. You will get compile errors because several variables must be defined with Dim statements. To prevent typos from ruining days and weeks of work 'Option Explicit' is NEEDED at the top of each code module. This prevents errors caused by missspellings and FORCES every variable to be DECLARED (e.g. dim i as Integer). http://www.cpearson.com/excel/DeclaringVariables.aspx

    See the following code with subtle changes in red.

    Please Login or Register  to view this content.
    Lewis

  15. #15
    Forum Contributor
    Join Date
    06-20-2011
    Location
    Auckland, NZ
    MS-Off Ver
    Excel 2013
    Posts
    165

    Re: Run Time Error '13' Type Mismatch

    thanks lewis for the code and no worries about the rep.

    i have changed my excel version.

    i will be using option explicit from now on.

    thanks again, lewis.

    best regards
    plasma33

+ 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 type mismatch 13
    By Dariusd7 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-15-2013, 05:11 PM
  2. [SOLVED] Run Time Error 13 Type Mismatch
    By pankaj8219 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-02-2013, 10:07 AM
  3. run-time error '13' type mismatch
    By dp1 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 09-06-2012, 02:43 AM
  4. [SOLVED] Run-time error '13': Type mismatch
    By btmtdk in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-26-2012, 06:32 PM
  5. Run-Time error 13: type Mismatch Help!
    By Fellhouse in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-28-2011, 04:58 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