-
Programmatically importing pictures from a URL
Hi!
I'm trying to automatically import a picture from an url. But I get the error message: Run time error 5152. This is not a valid file name.
It works fine if I do it manually through Insert -> Pictures. And pastes the URL into the file name field.
But if I try with the simple code:
Sub InsertPic()
'
' Test to import pic from url
'
'
Selection.InlineShapes.AddPicture FileName:= _
"https://removeofurl.com/imgapi/imgproxy/img?id=2459&width=1500px&fontsize=24px&zoom=100%25&unofficial=false&topleft =true&target=img-s1" _
, LinkToFile:=False, SaveWithDocument:=True
End Sub
I get the error. Is it that Word don't understand the url due to the &, = and % ? . Cause if you run with a direct link to a image it works as it should. We run a image creator at a webserver that creates the jpg.
Is it possible make Word understand that it is a jpg? Cause it works when you do it manually.
I'm running Word 365 (v 1905)
Thanks
BR
Jorge O
-
Try recording a macro while you import the url picture and see what it gives you.
-
Thanks, Tried that. Works fine when you record the macro and do it manual. But when you run the macro you get the Run time error 5152. Might be some authentication to our website but I also tried running Fiddler to see what happens and I just get 200 responses in the http traffic...
I have now solved it with some code that downloads the pictures to disc first and then adds it with Selection.InlineShapes.AddPicture
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules