Insert image from URL bookmark Microsoft word - vba

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?

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

Related

Adding file path of the image to be displayed in report in MS Access

so i need to put pictures in a report (some entry to have and some entry not to have), but the data need to be editable in excel, so i figure if i find a way to put it in path form (c:\folder\picture.bmp) is feasible, just don't know how.
I tried hyperlink, OLE object, simple text... nothing works. My VBA knowledge is almost zero.
Any suggestions?
Tnx in advance
I'm not sure if I understood your question clearly. You want to have a picture in excel that is editable. So you want changes in the picture from excel saved in the original file (c:\folder\picture.bmp)?
(I wanted to make a comment but i don't have enough reputation for this)
Maybe this could help in VBA:
Private Sub Worksheet_Picture()
Dim myPict as Picture
PictureLoc = "C:-Path-.png"
Set myPict = ActiveSheet.Pictures.Insert(PictureLoc)
End Sub

Use a Userform for MS Word to Input to Values in Form Fields

I am trying to automate a repetitive manual task for another department. They have a word template several pages long. They have to enter data several times each time they use it. Many of these are repetitive "fields". I thought about setting up custom form fields. But having them go through the navigation and know the field names to update them is not optimal. I found one solution to create a bookmark for each data input, and create links to that bookmark where it needs to be repeated - better but not optimal. I was hoping to create a userform where they can enter all the data and have it populate bookmarks, custom fields, to whatever.
I found a video that does this, but when I try the code, it does not update the bookmark. i created userform with Textbox1, and a CommandButton, and a bookmark in the document called MWDate. The code I am trying to get to work is:
Private Sub CommandButton1_Click()
Dim MWDate As Range
Set MWDate = ActiveDocument.Bookmarks("MWDate").Range
MWDate.Text = Me.TextBox1.Value
Me.Repaint
UserForm1.Hide
End Sub
This is a code example I grabbed and modified from the tutorial video. I don't know what the "Me." is. It does not populate the bookmark, which tells me it is not getting to the repaint line. Nor does it ever get to the hide line.
Anyone have a fix? Or a better way? Thanks for any help you can give.

How to force excel to open text in webbrowser?

I have to perform alot of searches in Google, so I made a Excel document that simply inserts the text into the google link:
"John" AND “Soccer” OR “Sport”
"Andre" AND “Soccer” OR “Sport”
For example in have the name "John"in cell A1 and I insert it in the following link.
https://www.google.nl/search?newwindow=1&q=%22&A1%22+AND+%E2%80%9CSoccer%E2%80%9D+OR+%E2%80%9CSport%E2%80%9D+&oq=%22&A1%22+AND+%E2%80%9CSoccer%E2%80%9D+OR+%E2%80%9CSport%E2%80%9D+&gs_l=serp.3...7614.32351.0.32567.17.17.0.0.0.0.345.1828.8j6j0j1.15.0....0...1c.1.64.serp..2.3.379...30i10k1.vLZ-hcrrdgg
And it comes out like this:
https://www.google.nl/search?newwindow=1&q=%22John%22+AND+%E2%80%9CSoccer%E2%80%9D+OR+%E2%80%9CSport%E2%80%9D+&oq=%22John%22+AND+%E2%80%9CSoccer%E2%80%9D+OR+%E2%80%9CSport%E2%80%9D+&gs_l=serp.3...7614.32351.0.32567.17.17.0.0.0.0.345.1828.8j6j0j1.15.0....0...1c.1.64.serp..2.3.379...30i10k1.vLZ-hcrrdgg
I made this for all the names by simply dragging it down. And these are all links that actually sends me to the page I want to be on. But what i can't is "CLICK ON THEM" no matter what i try i can't make those cells clickable Hyperlinks.
Next step is also that i want to print/Save them using Amyuni PDF. (this is not my biggest concern at the moment)
Is there any way to force the text to open up in a browser? Using VBA for example.
Thank You in advance, if you know a easier way to perform this I would like to hear that as well.
Kind Regards!
You should use the Hyperlink( ) Function
=HYPERLINK(link_location, [friendly_name])
you have this example from Microsoft, if the link you want is in A5 :
Sub test()
With Worksheets(1)
.Hyperlinks.Add Anchor:=.Range("a5"), _
Address:="http://example.microsoft.com", _
ScreenTip:="Microsoft Web Site"
End With
End Sub
you can modify Address:=... by the content of the cell

How can i set the name of a textbox in publisher?

I want to set the name of the text box so it can be easily accessed by code.
e.g
I am looking for an editing field similar to this
Thanks
There's a properties Window that can be accessed for each of the controls on the UI. There you may rename the controls. (Since you do not seem to have a VBA code yet and you want to rename the control from UI)
The other alternative. Record a macro, do some changes to the textbox (e.g. resize, change text etc). Then check the programme assigned default name of the textbox from the VBA editor. As you said, you can access the control via this default name and utilizing your VBA code (as you said), rename the textbox.
If you really want to be editing a worksheet object in Publisher you will have to get the OLEobject of the Shape and interpret it as an Excel.Application.
If you are just looking for a placeholder solution for Publisher documents, you could simply create a textbox that contains a certain string, then loop through all pages, all shapes on each page where HasTextFrame = msoTrue, and compare shape.TextFrame.TextRange.Text to your placeholder string. If it's the one you're after, you can do anything you want with the shape in question.
Sorry for the vague answer, but your images don't work anymore.
Edit: you can work with Shape.Name for your comparison (you mentioned this property in a comment), but I have no idea how you'd set the value from the interface, without using VBA, in the first place, so if you're making templates the approach I outlined above might be easier for users (see https://msdn.microsoft.com/EN-US/library/office/ff939233.aspx for Shape.Name). There is also a .Name property for page objects (https://msdn.microsoft.com/EN-US/library/office/ff940382.aspx), so you should be able to do something like ActiveDocument.Pages("page_name").Shapes("shape_name").TextRange.Text = "your content" once you've figured out how to actually set the name values
Edit 2:
You can also try to use search and replace as per Replacing Text in Microsoft Publisher Using Powershell if you don't need to do anything advanced beyond placing some text
Edit 3: Given the title of your question, unless you can figure something out with Publisher's interface, you can set the .Name property of the selected text box (or other shape) with dim shape = Selection.ShapeRange.TextFrame.Parent and shape.Name = "your_name". You can set the name of the selected page with ActiveDocument.ActiveView.ActivePage.Name="your_name". (Create a VBA macro that prompts you for names and you should be good to go)

Inserting a picture at a bookmark (OR how to tell if any list box items have been selected)

I'm new to VBA and still struggling a lot.
I have a list object on a useform that is populated with the file-names of the contents of the relative ".\logos\" directory. I want to insert the picture at a bookmark named bmLogo, but the code I've written (see below) doesn't do the trick.
If ListLogo <> Null Then
ActiveDocument.Bookmarks("bmLogo").Range _
.InlineShapes.AddPicture FileName:=ThisDocument.Path & "\logos\" & ListLogo
End If
Any tips? Also, if I could set a height and have the image scale to it without changing the aspect ratio that would be very useful!
Thanks,
Louis
EDIT 1: Right, so, bmLogo is the correct name of the bookmark, so that's not the problem.
I just used a msgbox to display '"path: " & ThisDocument.Path & "\logos\" & ListLogo' and it looks like the correct path. I'm using ThisDocument.Path as I want it to be relative so the document is more portable. I think I'll try with an absolute path for the time being and seeing if that work, if nothing else it should hint at where the bug is not.
EDIT 2: It works with an absolute path outside the IF statement and when I get a msgbox to print both the absolute and relative path they are identical. After commenting out the IF statement the relative method works find. I'm glad that it's working now but can anyone tell what the issue is with the IF?
EDIT 3: It turns out that my method for checking if something has been selected in the list box doesn't work at all. Instead I shall be iterating through each item in the list and checking if that one is selected. It's a pretty crude method but it'll do until I can find a better one.
For the record, this works for me in 2010, so I'm guessing there's either a problem with your filename (ListLogo), your bookmark (bmLogo), or else the filepath (ThisDocument.Path).
1:
Does the filename match the format you expect? Is it just the filename, or a full path? Does it include the proper extension?
2:
Does the bookmark exist in your document?
3:
Does ThisDocument refer to what you think it does? The simplification below works for me.
ActiveDocument.Bookmarks("TEST").Range.InlineShapes.AddPicture FileName:="P:\test.png"
I saved the .docx file in my P:\ path, so the following should have worked:
ActiveDocument.Bookmarks("TEST").Range.InlineShapes.AddPicture FileName:=ThisDocument.Path & "\test.png"
However, the path returned was my AppData directory. When I watched the ThisDocument object, I saw that it actually pointed to the Normal.dotm template, where the code was created when I recorded a macro to test this out.
Can you please verify that each of these three items are correct and what you expect?
ListLogo
bmLogo
ThisDocument