VBA code for adding a picture (that is in embedded in an Excel worksheet) to a Word document

Mattantaliss

Board Regular
Joined
Sep 6, 2005
Messages
52
Hello,

First off, this is all with Office 2010 running on Windows 7.

I have inserted a (not linked) picture in an Excel worksheet. The idea is to be able to send the single Excel file to someone and have the picture included, instead of sending two separate files. Now what I want to do is use that picture in the header of a Word document that I am creating via VBA code. The problem I am running into is getting the picture from the Excel worksheet to the Word document and positioning it correctly (at the top of the page).

On one hand, I could do something like
Rich (BB code):
appWord.ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Shapes. _
  AddPicture(Filename, LinkToFile:=False, SaveWithDocument:=True, _
  Top:=InchesToPoints(-1 * HeaderMarginInches)).RelativeVerticalPosition = _
  wdRelativeVerticalPositionPage
or, on the other hand, I can copy the image and do
Rich (BB code):
appWord.ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Range. _
  PasteSpecial Link:=False, Placement:=wdInLine, DisplayAsIcon:=False

Note: appWord is a Word.Application, and the italicized bits are placeholders for what I would actually have in there.

With the first option, I need to know the filename. That means I need to either have the image be a separate file or I need to know the full path of an embedded picture. With the second option, I can not figure out how to access and reposition the pasted image in Word.

Does anyone know how I can go about getting the desired outcome? At this point, I'm basically hunting for something like a version of .AddPicture that will take a shape instead of a string (filename).
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce

Forum statistics

Threads
1,216,084
Messages
6,128,724
Members
449,465
Latest member
TAKLAM

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