+ Reply to Thread
Results 1 to 8 of 8

Stuck in VBA

  1. #1
    Registered User
    Join Date
    12-21-2016
    Location
    Netherlands
    MS-Off Ver
    2013
    Posts
    7

    Question Stuck in VBA

    Hi everyone,

    I'm stuck in VBA. I'm probably missing a simple part but I can't figure it out.
    I've made a userform that collects information out of a database. Now the difficult part: When the name changes, it should download the corresponding picture (link in Cell offset 37). Sometimes it can't download that files, in that case it should show a "no picture available" picture (link in offset 39).
    The macro works fine untill the Error part, when it can't download the picture...

    Here's the part of macro so far:

    Private Sub CboMedew_Change()
    Dim url_path As String
    Dim file_path As String

    url_path = rName.Offset(0, 37).Value
    file_path = ThisWorkbook.Path & "\" & "Image.png"
    ' Download picture
    DownloadFilefromWeb url_path, file_path
    On Error Resume Next
    url_path = rName.Offset(0, 39).Value
    file_path = ThisWorkbook.Path & "\" & "Image.png"

    With Image2
    .Picture = LoadPicture(file_path)

    End With
    ' Delete Saved file
    Kill file_path

    End Sub
    Last edited by Roeldh; 12-22-2016 at 05:36 AM.

  2. #2
    Forum Expert
    Join Date
    02-14-2009
    Location
    .
    MS-Off Ver
    ................
    Posts
    2,840

    Re: Stuck in VBA

    You can use the DIR function to check the image exists before trying to load it to the image control, or use formal error handling - which should be included with any non trivial code in any case.

  3. #3
    Registered User
    Join Date
    12-21-2016
    Location
    Netherlands
    MS-Off Ver
    2013
    Posts
    7

    Re: Stuck in VBA

    I've kinda new to VBA and never used the DIR function before. But I'll google that one. I tried the error handling but that doesn't do what I want so far

  4. #4
    Forum Expert
    Join Date
    02-14-2009
    Location
    .
    MS-Off Ver
    ................
    Posts
    2,840

    Re: Stuck in VBA

    I tried the error handling but that doesn't do
    Then post the code you did use for the error handling...

  5. #5
    Registered User
    Join Date
    12-21-2016
    Location
    Netherlands
    MS-Off Ver
    2013
    Posts
    7

    Re: Stuck in VBA

    This is the main line:

    url_path = rName.Offset(0, 37).Value
    file_path = ThisWorkbook.Path & "\" & "Image.png"
    ' Download picture
    DownloadFilefromWeb url_path, file_path

    When there isn't a picture, it should follow this line:

    On Error Resume Next
    url_path = rName.Offset(0, 39).Value
    file_path = ThisWorkbook.Path & "\" & "Image.png"

    I tried it with this, but that doesn't work...

    url_path = rName.Offset(0, 37).Value
    file_path = ThisWorkbook.Path & "\" & "Image.png"
    ' Download picture
    DownloadFilefromWeb url_path, file_path
    On Error Resume Next
    url_path = rName.Offset(0, 39).Value
    file_path = ThisWorkbook.Path & "\" & "Image.png"

  6. #6
    Valued Forum Contributor kasan's Avatar
    Join Date
    07-22-2009
    Location
    Riga, Latvia
    MS-Off Ver
    Excel 2010
    Posts
    680

    Re: Stuck in VBA

    You also could use file attributes to check if file exists
    Please Login or Register  to view this content.

  7. #7
    Forum Expert
    Join Date
    02-14-2009
    Location
    .
    MS-Off Ver
    ................
    Posts
    2,840

    Re: Stuck in VBA

    'On Error Resume Next' is NOT error handling - it is simply ignoring any errors that are raised and really should not be used unless you know exactly what you are doing and are coding to resolve any errors that are raised.

    Read the link in my first post.

  8. #8
    Registered User
    Join Date
    12-21-2016
    Location
    Netherlands
    MS-Off Ver
    2013
    Posts
    7

    Re: Stuck in VBA

    Thnx a lot Cytop!
    I read the article and learnt a lot. I found out that the first part results in a Error (I can't figure out what goes wrong) so I switched the two parts and now it works fine (with the on Error resume next :-) ).

+ 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. Just Stuck
    By kempdog34 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-01-2014, 04:58 PM
  2. Stuck at work and stuck on a count function
    By gregfetzer in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 10-24-2012, 12:47 AM
  3. Not sure what to do(Stuck)
    By sshanahan19 in forum Excel General
    Replies: 2
    Last Post: 03-22-2012, 01:51 PM
  4. Stuck
    By ROPI in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 07-25-2010, 05:28 AM
  5. [SOLVED] Please help, I'm stuck
    By Ben in forum Excel General
    Replies: 2
    Last Post: 03-30-2006, 04:55 PM
  6. stuck
    By darkbearpooh1 in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 02-10-2006, 06:30 PM
  7. Stuck
    By PaulOakley in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 07-13-2005, 01: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