Use VBA to paste an image in a Winword document using a URL

Hi

I work with PRTG and provide one of my clients with a weekly reports.

I'd like to automate the process by using VBA to collect graphs from PRTG and insert them into a table in Winword 2013.

The URL look like this :
http://XXX.XXX.XXX.XXX:8080/chart.png?type=graph&width=400&height=200&graphid=2&id=5493

Open in new window


When I load this in a browser I obtain the expected result : a graph in PNG format

Is it possible to use VBA in order to collect and insert these graphs into my word document ?

thanks
yann
Yann ShukorOwnerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

MacroShadowCommented:
Try this:
Sub InsertURLGraphic()
   With Dialogs(wdDialogInsertPicture)
       .Name = "http://XXX.XXX.XXX.XXX:8080/chart.png?type=graph&width=400&height=200&graphid=2&id=5493"
       .Execute
   End With
End Sub

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Yann ShukorOwnerAuthor Commented:
I tried with both formats: PNG and SVG
Same error, is the problem with PRTG or Winword ?

Untitled-1.jpg
0
MacroShadowCommented:
This works for me:
Sub InsertURLGraphic()
   With Dialogs(wdDialogInsertPicture)
       .Name = "http://experts.cachefly.net/files/2014/05/29/3c477867-0ec6-4a3b-9d33-9f35bfe2021a.JPG"
       .Execute
   End With
End Sub

Open in new window


And so does this:
Sub InsertURLGraphic()
   With Dialogs(wdDialogInsertPicture)
       .Name = "http://experts.cachefly.net/files/2015/07/15/792b93a5-3afc-4142-a1a8-f63589776532.png"
       .Execute
   End With
End Sub

Open in new window


My guess is that the problem you're facing stems from the fact that the url doesn't point to an existing picture, it generates it.
0
Yann ShukorOwnerAuthor Commented:
Thank you MacroShadow
I will query Paessler and get back to you
0
MacroShadowCommented:
What did they say?
0
Yann ShukorOwnerAuthor Commented:
They confirmed that there was effectively no image, just a link that generates the image on the fly

They offered the following alternative:

Sub Example1()
	Selection.InlineShapes.AddPictrure FileName:= _
	"http://XXX.XXX.XXX.XXX:8080/chart.png?type=graph&width=400&height=200&graphid=2&id=5493", _
        LinkToFile:=False, SaveWithDocument:=True
End Sub

Open in new window


What do you think ?

regards
yann
0
MacroShadowCommented:
Did you try it?
0
Yann ShukorOwnerAuthor Commented:
Ok, I just tested it and it works
I did however have to set the image format to PNG
because Word displayed a square with "This image cannot be displayed" when the format was set to SVG
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Office

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.