Pushing an image from Excel to Word along with other bookmarks

m_in_spain

Board Regular
Joined
Sep 28, 2018
Messages
64
Office Version
  1. 365
Platform
  1. Windows
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
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
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
 
Upvote 0
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!!)
 
Upvote 0

Forum statistics

Threads
1,214,601
Messages
6,120,460
Members
448,965
Latest member
grijken

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