Jumat, 25 April 2014

Re: [ExcelVBA] Find if image has hyperlink

 

Dear Derek,


I did not want to write:
on error resume next.
I did not need per se to find an error trapping code.
Maybe the problem is that I did not understand your code fast enough, and as I said previously, I had seen Tim's reply before I say yours.

So to tell the truth, I did not try the code, but I will try it tonight (I can't do that during daytime, when I need the sheet), because I just understood the line where it would do what I wanted.

I will tell you how it went.

Although Tim's code works well, to understand you code would learn me new ways to handle similar problems

Thank you very much, I'll be back on this.

Louise

PS: I had to send this a second time. When I first tried, the email came back with a Delivery Status Notification(Failure)
I was replying to the address: mortal2k@tri.blackberry.com 
It is not the first time that this happens.
Do you like your Blackberry? Although loosing for the moment I have a long position on Blackberry. (Own a few shares)


Le --23042014 à 13:08, Derek Turner <g4swy@yahoo.com> a écrit :



Dear Louise

This worked for me :-

Sub Find_Image_URL()
    Dim Shp As Shape, strUrl As String
    For Each Shp In ActiveSheet.Shapes
        strUrl = "0"
        On Error Resume Next 
        strUrl = Shp.Hyperlink.Address
On Error GoTo 0
        Range(Shp.TopLeftCell.Address) = Not strUrl = "0"
    Next Shp
End Sub

I took out the intersect thing to simplify the testing. You will have to put it back. The strUrl = "0" allows for testing your old web pages.

The proper way to do error trapping in VBA is to surround the offending line with the error trapping code. Do not use On Error Goto Label because this creates spaghetti code. Keep the trapping in-line. 

The On Error Goto 0 switches off the Resume Next immediately after the line where the error is expected so if there are later errors you will not be confused.

To be more professional you might want to test the error in case it is not the one you expect :-

On Error Resume Next
        strUrl = Shp.Hyperlink.Address
        nErrorNumber = Err.Number
        sErrorDescription = Err.Description
        On Error GoTo 0
        Select Case nErrorNumber
            Case 0, 1004
            Case Else:   MsgBox sErrorDescription, vbCritical, "Unexpected Error"
        End Select

By the way your InStr(strUrl, "0") failed for me because my test URL had a zero in it.

__._,_.___
Reply via web post Reply to sender Reply to group Start a New Topic Messages in this topic (15)
----------------------------------
Be sure to check out TechTrax Ezine for many, free Excel VBA articles! Go here: http://www.mousetrax.com/techtrax to enter the ezine, then search the ARCHIVES for EXCEL VBA.

----------------------------------
Visit our ExcelVBA group home page for more info and support files:
http://groups.yahoo.com/group/ExcelVBA

----------------------------------
More free tutorials and resources available at:
http://www.mousetrax.com

----------------------------------
.

__,_._,___

Tidak ada komentar:

Posting Komentar