Pushing an image from Excel to Word along with other bookmarks

m_in_spain

New Member
Joined
Sep 28, 2018
Messages
48
Hi Everyone.
Firstly let me say I am completely new to this and have found this forum just today. I have scratched around but cannot find some code for what i am trying to do.
Next is the advance apologies if there already is an answer to this and also if i have not described my problem/what i have done/want to do very clearly. I usually do get better with practice!

I have for years working with a 20 worksheet excel file to produce a costing. Recently i started to "automate" it so that for a few choices on an input page, I can produce a costing sheet for the items wanted by any particular customer. Nothing too hard there.
I then thought it would be nice to take my standard Word document to produce a quotation. After a lot of internet searching i discovered this was possible using bookmarks in Word. It is all going swimmingly. I managed to find, modify and insert my first ever bit of code, so which i click my "make doc" button, the word template opens the data from excel goes in and i have my document.
Next comes the part which is foxing me.
I discovered how to select one of 8 different pictures I have stored in an excel worksheet called pictures, depending on the value of a certain cell, this picture corresponds to the particular unit i have costed. I can then copy the correct picture to another worksheet i have made called transfer, (ready to transfer to my word doc)

What i am now trying to do is to take that picture and insert it into a particular place in the Word document at the same time as I send over the mentioned data. Once i have this for one picture, i need to repeat it many times with other pictures to complete my document.

Sorry for such a long winded question, ANY help will be greatly appreciated, please make any answers simple for old me to understand!
Many many thanks
 

Some videos you may like

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.

Worf

Well-known Member
Joined
Oct 30, 2011
Messages
4,010
Welcome to the Board

The following example shows how to transfer a picture from Excel to Word.

Code:
' Excel module
Sub Macro2()
Dim wapp As Word.Application, bm As Bookmark, sh As shape, wdoc As Document
Set sh = ActiveSheet.Shapes("image1")         ' your image name here
On Error Resume Next
Set wapp = GetObject(, "Word.Application")      ' Word is already open
Set wdoc = wapp.ActiveDocument
If wapp Is Nothing Then
    Set wapp = New Word.Application
    ' open template if there is no active document
    Set wdoc = wapp.Documents.Add(Template:="c:\temp\my_letter.dotx", _
    NewTemplate:=False, DocumentType:=0)
End If
Set bm = wdoc.Bookmarks("pic1")  ' your bookmark name here
If bm Is Nothing Then
    MsgBox "Bookmark not found."
    Exit Sub
End If
On Error GoTo 0
sh.Copy
bm.Range.Paste
End Sub
 

m_in_spain

New Member
Joined
Sep 28, 2018
Messages
48
Many many thanks.
I used bits of that and added it to what i has already done, as i had already named a few things. However you gave me the bit i was missing and searching for!
I am finding that through changing just one piece at a time, running it, if it works carry on, if not google why now...type of approach seems to get there in the end. I think i am finding it interesting too! (Only think at moment!!)
 

Watch MrExcel Video

Forum statistics

Threads
1,109,258
Messages
5,527,662
Members
409,781
Latest member
Maxcwy2020

This Week's Hot Topics

Top