Reputation: 172
is there a way that I can get the image dimensions of an online image if I have the link? For example, how would I get width and height in VBA for https://www.google.com/images/srpr/logo11w.png
Thanks!
Jasper
Upvotes: 0
Views: 1788
Reputation: 31364
Assuming your image URL example is pretty close to what you really want, you can do it with a little 'web scraping':
First, you must add the following two references
Sub extract()
Dim IE As InternetExplorer
Dim html As HTMLDocument
Set IE = New InternetExplorerMedium
IE.Visible = False
IE.Navigate2 "https://www.google.com/images/srpr/logo11w.png"
' Wait while IE loading
Do While IE.Busy
Application.Wait DateAdd("s", 1, Now)
Loop
Set html = IE.document
Dim webImage As Variant
Set webImage = html.getElementsByTagName("img")
'Debug.Print webImage(0).Width
'Debug.Print webImage(0).Height
MsgBox ("Image is " & webImage(0).Width & " x " & webImage(0).Height)
'Cleanup
IE.Quit
Set IE = Nothing
End Sub
Results:
Upvotes: 1