Insert an Image into Word document in a specified location?? Word/VBA

dragon-goddess1990

New Member
Joined
May 18, 2011
Messages
25
Word 2010

Scenario 1) I would like to be able to get the user to browse for an image (electronic signature) - I dont know how to create a browse control to do this

Scenario 2) I would like to be able to insert a header image into a document in a specific location - I dont know how to reference a specific location / coordinates in the document (bookmark isnt ideal as the header image needs to sit perfect and fill the width etc)

Please help :)

Thanks
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Scenario 1) If you want to be able to browse to a particular location and select the image to insert, what do you want to achieve that the Insert|Picture dialogue doesn't provide?

Scenario 2) Is there a reason for not using a template with the image already located & sized to meet your requirements? Aside from that, is it always the same image and location in the document?
 
Upvote 0
1) They will be loading a userform before the document so they need to browze to an image from there and it insert it into a bookmark. It will affectively be their electronic signature.

2) Background of scenario - the user is filling in a userform before they have access to touch the document - they need to choose if it will be either an electronic document or paper. Electronic will insert the header, paper will adjust the margins/print settings. I want to be able to specify where the image goes (i.e. cm from top or whatever)
 
Upvote 0
For (1) you could use code like:
Code:
Sub Demo()
Dim StrPic As String, iShp As InlineShape, Rng As Range
With Application.Dialogs(wdDialogInsertPicture)
  If .Show = -1 Then
    StrPic = .Name
    With ActiveDocument
      .Undo
      Set Rng = .Bookmarks("BkMk").Range
      Rng.Text = vbNullString
      Set iShp = .InlineShapes.AddPicture(FileName:=StrPic, LinkToFile:=False, Range:=Rng)
      With iShp
        .LockAspectRatio = True
        .Height = InchesToPoints(1)
      End With
      With Rng
        .End = .End + 1
      End With
      .Bookmarks.Add "BkMk", Rng
    End With
  End If
End With
End Sub
As for inserting a header in a specific location, if you mean somewhere other than on the first page, that can entail a fair bit of work; otherwise, it's best to have a default document (eg the print version) and, if they choose the alternate version, simply create a new document from the alternate version's template and use that. That way, you shouldn't need to worry about where the image goes.
 
Upvote 0
1) What controls do I need to achieve this? (i.e. textbox, button etc)

2) Ive debated it - wanted to check if I could. Though it would overlap with another template I am creating which I need them to browze for a 3rd Party/External logo and it be inserted into the document in a specific location - can I create a text frame/object and tell it to go in there?
 
Upvote 0
1) Do you already have the userform? If so, add a command button and drive the process from that.

2) Whenever you create a document, it really should be done from a template that's been designed for the purpose, rather than taking different template then trying to modify the document it creates. So, while you could have, say, a table into which you put a logo, it would be better to use a template with the logo and no table.
 
Upvote 0
1)Yes I have a userform. So it would be buttonname_click

2) im trying to create 1 template from many one of the key objectives of the project is to reduce duplication (including templates) I guess if I just do the browse idea (1) and add a 3rd party logo bookmark that would do it. My main bug bare was the trying to create the text box for the URL and browse button.

Taa
 
Upvote 0
Re: 2
Yes, you could use the same basic approach as for (1) and, if it's for a letterhead, it's really not particularly complicated to put the logo into the page header (without even using a bookmark) and, say, configure the document with a different first page layout, so the logo only appears on the first page. Of course, if you already know which client you're doing the letterhead for, and the logos are all stored in the same folder, you can do away with the browse code and simply have the code look in the folder for the appropriate client logo. However, things do get complicated if the logos need resizing to fit the space available or they have to be put in different positions for different clients.
 
Upvote 0
Hiya

For any headers I do I'd probably start the document off with it and just remove it if they choose paper.

Unfortunately I don't know what logos they would put in or
where from this is why I needed the browse option :)

Thing is our company is large and complicated. We are currently rolling out SharePoint 2010. This is a generic letter template so anyone needs to be able to use it. I've had to for example have the userform go find heir outlook signatures, list them so they can insert it into the signature so that they dont have to keep putting their details in every time or save a copy (defo don't want duplicates :P)

I might have a stab at the bbrowse thing see if I ccan get it to work. When thu browse using the button how will they then know they have chosen one correctly when they ccontinue with the userform? I assume the code you kindly submitted doesn't put the file path in a text box?

Regards
 
Upvote 0
OK, given that you're trying to produce something for multiple branches, I'd be inclined to approach the letterhead issue slightly differently.

Assuming each branch has its own group folders at least, if you store the logo file for each branch in the same folder as the template, and the logo files all have the same filename, an INCLUDEPICTURE field can be used to import the logo. Then all you need the macro to do is to unlink the field upon the creation of the new document. If you wanted, the same principle can be extended to the importation of the entire letterhead, via an INCLUDETEXT field.

As for the browser code, you can change it's file display configuration to show file icons (if it's not already doing so), the same as you can do for Windows Explorer. FWIW, I wrote the code to prevent duplicates. Run it a second time and the first image will be replaced.
 
Upvote 0

Forum statistics

Threads
1,225,637
Messages
6,186,137
Members
453,339
Latest member
Stu61

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top