0

I have a image URL contained in my sql database. I create a bookmark for that column in the word document (this works fine).

Now I want to use the image URL that is passed from the database to insert an image.

I have tried hyperlink (does not work and does not display image).
I have tried Quick Parts - IncludePicture (does not work).

I have been Googleing and have not found anything that works.

Ok let me simplify this. I want to insert a image using an URL. You can do this in alot of different ways I know.

For instance using Quick Parts and the selecting IncludePicture you would the past the URL of the picture and BAM image inserted.

Now I want to do exactly that with one exception. The URL is a microsoft word bookmark that I get from my database. For some reason this does not want to work. I have also checked the bookmark data and it is correct and yes it is a valid URL because if I copy and paste it from the database in the way I described above it works.

So is there any other way to do this?

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
BulletVictim
  • 13
  • 1
  • 5
  • 1
    do you want to do it manually or using any code (vba?). if code- do you have any initial code already?... to make it clear: image from web based on url to bookmark range? – Kazimierz Jawor Jun 20 '13 at 15:26
  • What I have is a template composed mostly from bookmarks so not really manually but I am not generating it from code either. – BulletVictim Jun 21 '13 at 05:00
  • The Image I want to add is a static google maps image and the URL is a varchar in my database – BulletVictim Jun 21 '13 at 05:10
  • this question is quite similar to previous one of yours. to get an answer you need to be more precise, answer questions from comments, provide as much information as possible... Anyway, I would say it's possible what you need and could be done with word-vba, but I don't know how to do it with C#,asp.net and other (which you refer in the other question). So, be precise to get help! – Kazimierz Jawor Jun 21 '13 at 06:00
  • I am trying to be as precise as possible, but due to the terms of my employment I am not able to give out a lot of information about this as these are legal documents. If you know how to do it with word-vba that would be greatly appreciated. The reason I posted this question is because the requirements on how to do it has changed since in the previous question I was trying to get an image directly from the google maps api v3 control I was using. I am now doing this completely differently. – BulletVictim Jun 21 '13 at 06:09
  • I'll try to help you a bit later with some vba code... – Kazimierz Jawor Jun 21 '13 at 08:54

1 Answers1

0

To be honest I still don't know where is exactly your problem. I assumed that you have knowledge and code to take both bookmark name and url from your database using VBA. If so, there would be quite simple code which would allow you to load picture from web to bookmark in your word document.

Below is the code I have tested with half of success. If I add any picture it will work fine. But will not work with url of active google map. I have no idea what you you mean with 'static google map' (in comment), you didn't provide any example therefore you need to make your own test.

Before you run this for test be sure you have two bookmarks in your active document: bookmark_logo and bookmark_poland. Hope this will help a bit.

Sub Insert_picture_To_Bookmark()

    Dim mapURL As String
    Dim soLOGO As String

    soLOGO = "http://cdn.sstatic.net/stackoverflow/img/apple-touch-icon.png"
    ActiveDocument.Bookmarks("bookmark_logo"). _
                    Range.InlineShapes.AddPicture _
                    soLOGO, True, True

    mapURL = "https://maps.google.pl/maps?q=poland&hl=pl&sll=50.046766,20.004863&sspn=0.22047,0.617294&t=h&hnear=Polska&z=6"
    ActiveDocument.Bookmarks("bookmark_poland"). _
                    Range.InlineShapes.AddPicture _
                    mapURL, True, True

End Sub
Kazimierz Jawor
  • 18,861
  • 7
  • 35
  • 55
  • Sorry for only getting back to you now, been away from my pc for the weekend. You are a saint man this helps a lot. It works great there is just one small question. Is there a way to set the string to the Bookmark? This document needs to be created dynamically for different locations(different location for each document created). You have really helped a lot and I really appreciate all the effort. – BulletVictim Jun 24 '13 at 06:20
  • This is what the code I generated looks like: Sub Insert_picture() Dim Google As String Google = "http://maps.googleapis.com/maps/api/staticmap?center=(-26.2041028, 28.047305100000017)&zoom=17&size=500x500&markers=size:large%7Ccolor:red|(-26.2041028, 28.047305100000017)&sensor=false&region=ZA" ActiveDocument.Bookmarks("MAPURL").Range.InlineShapes.AddPicture Google, True, True End Sub – BulletVictim Jun 24 '13 at 06:21
  • to replace text string within your bookmark you need to go this way: `ActiveDocument.Bookmarks("MAPURL").Range.Text = "here is the map of:"`. However, it will remove bookmark. [Here is the solution](http://stackoverflow.com/questions/2006077/copy-text-from-range-in-excel-into-word-document/2418403#2418403) which help you to deal with that problem. – Kazimierz Jawor Jun 24 '13 at 09:31
  • KazJaw Thank you for all your help. This did not work for me but I had it confirmed that your method works in the way that I described the problem. Its just the way that my document was populated that knocked everything else out. – BulletVictim Jun 24 '13 at 10:44