Link to home
Start Free TrialLog in
Avatar of Yann Shukor
Yann ShukorFlag for France

asked on

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
ASKER CERTIFIED SOLUTION
Avatar of Joe Howard
Joe Howard
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Yann Shukor

ASKER

I tried with both formats: PNG and SVG
Same error, is the problem with PRTG or Winword ?

User generated image
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.
Thank you MacroShadow
I will query Paessler and get back to you
What did they say?
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
Did you try it?
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