Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Ok this might not be as much a programming question as just a how the hell do I do it question.

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 my ass of for the past week and have not found anything that works.

ANY HELP PLEASE???????????


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?


I have been supplied with word-vba code that looks something like this.

VB
Sub Insert_picture()

Dim Google As String

<pre>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


So now my question(using this code). Is there a way to set the Google string to the MAPURL bookmark?
I need to dynamically generate the image for different locations. (Different location for each document that is greated)
Hope this helps make what I am looking for a bit clearer

Again any help will be greatly appreciated.
Posted
Updated 23-Jun-13 21:03pm
v5

Check this code:

VB
Sub Insert_picture()

Dim Google As String

ActiveDocument.Bookmarks("MAPURL").Select
Google = Selection.Text

ActiveDocument.Bookmarks("MAPURL").Range.InlineShapes.AddPicture Google, True, True

End Sub



Be aware to have the placeholder bookmark only covering the url, and nothing else.
 
Share this answer
 
v2
Comments
BulletVictim 24-Jun-13 3:01am    
That is just the commenting of the site that did removed the http protocol.
Zoltán Zörgő 24-Jun-13 4:00am    
I tried it, and it is working for me in Word 2010.
BulletVictim 24-Jun-13 4:06am    
Yes I know it works if you use a static URL. I need to use the bookmark to set the URL. So basically I need to select the text from my Bookmark and set the Google string to that text
Zoltán Zörgő 24-Jun-13 4:28am    
How exactly? A bookmark has no value.
BulletVictim 24-Jun-13 4:15am    
I have tried doing it like this. Google = ActiveDocument.Bookmarks("MAPURL").Range.Text
If i try to implement it I get a Run-time error '5152': This is not a valid file name.
Try one of the following:
*Check the path to make sure it was typed correctly.
*Select a file from the list of files and folders.
Here I check for the bookmark in the database and if it contains the mapurl bookmark it then takes the placeholder bookmark on the document and sets its text to null and the inserts the image at the bottom of the document(where the bookmark is located)

VB
If MyBookMarks.Item(bookmark).Name = "mapurl" Then

                    MyBookMarks.Item(bookmark).Range.Text = ""

                    Dim oRange As Object = MyBookMarks.Item(bookmark).Range
                    Dim saveWithDocument As Object = True
                    Dim missing As Object = Type.Missing

                    appWord.Application.Selection.InlineShapes.AddPicture(cmd.Columns.Item(bookmark).ToString(), missing, saveWithDocument, oRange)
                Else
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900