Converting a Image URL to Actual Image Size

ahobbs01

New Member
Joined
Jan 13, 2023
Messages
16
Office Version
  1. 365
Platform
  1. Windows
I used this code from another VBA question thread but I received an error. I am trying to extract the image from the URL without changing the size of the image.It worked for some of the images but then errored out.
1684787484951-png.92080

1684787461568-png.92079
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
I used this code from another VBA question thread but I received an error. I am trying to extract the image from the URL without changing the size of the image.It worked for some of the images but then errored out.
1684787484951-png.92080

1684787461568-png.92079
I changed it to be Range("D2", Cells (Rows.Count, "D") .End (xlUP) ) and that still did not remove the error
 
Upvote 0
The RowHeight Property ranges from 0 to 409 points so you are probably getting that error because the Picture size (Height) exceeds 409 points.
 
Upvote 0
The RowHeight Property ranges from 0 to 409 points so you are probably getting that error because the Picture size (Height) exceeds 409 points.
Yes. Is there a way to tell it to skip that one if it errors out like that?
 
Upvote 0
Yes. Is there a way to tell it to skip that one if it errors out like that?
Skip it with an IF clause something along these lines :
If .Height * 0.75 <= 408 Then URL.EntireRow.RowHeight = .Height End If

EDIT: I am not entirely sure the Picture object returned by the Pictures.Insert Function is in Pixels or in Points.
Try removing *0.75 and see if it works as well.
 
Last edited:
Upvote 0
Where does the IF statement go? I've tried different ways and I get the same error
1684846235724.png
 
Upvote 0
Please, place your code inside Code Tags </> so anyone wanting to help can copy it for testing.

You are getting the error because you still have the following line before End With
URL.EntireRow.RowHeight = .Height
Remove that line and the error should not happen.
 
Upvote 0
Please, place your code inside Code Tags </> so anyone wanting to help can copy it for testing.

You are getting the error because you still have the following line before End With
URL.EntireRow.RowHeight = .Height
Remove that line and the error should not happen.
.Height is now Invalid or unqualified reference.

VBA Code:
Sub InsImg()

    Dim URL As Range
        
    For Each URL In Range("D2", Cells(Rows.Count, "D").End(xlUp))
        With URL.Parent.Pictures.Insert(URL.Value)
            .Left = URL.Offset(0, 1).Left
            .Top = URL.Offset(0, 1).Top
            
        End With
            
            If .Height * 0.75 <= 408 Then
            URL.EntireRow.RowHeight = .Height
            End If
        
                
    Next

End Sub
 
Upvote 0
VBA Code:
Sub InsImg()
    Dim URL As Range     
    For Each URL In Range("D2", Cells(Rows.Count, "D").End(xlUp))
        With URL.Parent.Pictures.Insert(URL.Value)
            .Left = URL.Offset(0, 1).Left
            .Top = URL.Offset(0, 1).Top
            If .Height * 0.75 <= 408 Then
                URL.EntireRow.RowHeight = .Height
            End If
        End With
    Next
End Sub

Also, try the smae code but without the * 0.75 and see what happens
 
Upvote 0
Solution
VBA Code:
Sub InsImg()
    Dim URL As Range    
    For Each URL In Range("D2", Cells(Rows.Count, "D").End(xlUp))
        With URL.Parent.Pictures.Insert(URL.Value)
            .Left = URL.Offset(0, 1).Left
            .Top = URL.Offset(0, 1).Top
            If .Height * 0.75 <= 408 Then
                URL.EntireRow.RowHeight = .Height
            End If
        End With
    Next
End Sub

Also, try the smae code but without the * 0.75 and see what happens
Removing the * 0.75 solved it. Thank you!
 
Upvote 0

Forum statistics

Threads
1,214,989
Messages
6,122,622
Members
449,093
Latest member
catterz66

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top