Image in output to Word Document (1 Viewer)

Design by Sue

Registered User.
Local time
Today, 03:54
Joined
Jul 16, 2010
Messages
640
We need to replicate an Access report we have in Microsoft Word. The report has a fixed, small image in the header and so we embedded it in the report (it is not in an external file). To put this image in the Word document the only way we’ve come up with is shown in the code below.

Code:
Dim apWord As Word.Application
Dim doc As Word.Document
Set apWord = CreateObject("Word.application")
doc.Shapes.AddPicture "G:\Images\Sinful Banner.bmp", False, True, 0, 0, 540, 42


Which requires an external image file. We really would like to avoid this. We could make a template Word document, but that too would be an external file. We know how to put this image in a table as an OLE object, but can’t find any way to get it from the table into the Word document. Can anyone tell us if this is possible and better yet how to do it?

Thanks
Sue
 

burrina

Registered User.
Local time
Today, 05:54
Joined
May 10, 2014
Messages
974
Are you trying to automate this or simply put the same bmp file in word as in access?
If the latter, then manually copy and paste.

P.S. Here is a link that may suit your needs.

http://www.lebans.com/ReportUtilities.htm


HTH
 
Last edited:

Design by Sue

Registered User.
Local time
Today, 03:54
Joined
Jul 16, 2010
Messages
640
burrina -this needs to be automated.

skipepl - will check out the links - thanks

Sue
 

burrina

Registered User.
Local time
Today, 05:54
Joined
May 10, 2014
Messages
974
I believe your solution is:
1. Export to pdf
2. Do a mail merge
 

vbaInet

AWF VIP
Local time
Today, 10:54
Joined
Jan 22, 2010
Messages
26,374
Thanks but no help here - anyone else??

Sue
Why don't you ask, "any other ideas" rather than "anyone else". And if something doesn't work, explain exactly what you tried and what the outcome was.
 

Design by Sue

Registered User.
Local time
Today, 03:54
Joined
Jul 16, 2010
Messages
640
Sorry "any other ideas" was what I meant by "anyone else".

As I stated in my first post is that we are trying to avoid having an external file for the artwork that needs to be included in the Word document. The suggestions made, though I thank folks for taking time to offer suggestions, have not answered my original question. This needs to be automated - it can't be accomplished by cutting and pasting. It can't be exported to pdf because the users need to be able to edit the output and they do not have access nor the training for Acrobat. I can't see anyway to do a mail merge to accomplish recreating this form in Word - the need to give the user in Access a button to click which will create a document in Word with the same layout as is in Access as a report. This involves adding a header that is not stored in Access (currently). So my question is how can we automate the creation of this Word document to include the addition of the jogs without keeping the jpg files in a folder on the server - rather we would like the images to be saved within the Access database and called from there.

I am not sure that is any clearer than my first post but I don't know how to express it any better.

Sue
 

darbid

Registered User.
Local time
Today, 11:54
Joined
Jun 26, 2008
Messages
1,428
Hey Designed by Sue,

I have done something similar however in my case my source was an excel chart that I copy and paste into word. I must admit I do not understand if it is the whole report or an image you want in word but here is how I do it in Excel.

Code:
'This is take out of a with section. You need to have your chart object here.
.Chart.Select

'This copies it as a picture to the clipboard.
.Chart.CopyPicture Appearance:=xlScreen, size:=xlScreen, Format:=xlPicture


'Paste into Word as metafile image.
'objWord is a reference to your Word Application.
objWord.Activate

With objWord.Selection

'This is a bookmark which is added to the word document. So I go to that point.
    .GoTo What:=wdGoToBookmark, name:="chart"
    '.PasteSpecial DataType:=wdPasteEnhancedMetafile  (intentionally commented out. try with or without it.)
    .PasteAndFormat (wdPasteDefault)
End With

'Then to fix it up in my case I select the image and make it an inlineshape.
objWord.ActiveDocument.Shapes("Picture 2").Select

objWord.Selection.ShapeRange.ConvertToInlineShape
 

vbaInet

AWF VIP
Local time
Today, 10:54
Joined
Jan 22, 2010
Messages
26,374
So Sue, I've had a quick look at this and it seems that the only two ways of adding an image to a Word document is through the path to an image file on disk or pasting the image from the clipboard

How is the image saved in Access? In an OLE field or it's embedded in an Image control?

Have you considered creating a Word template that already has the image embedded in it, and using that template to create your Word doc? This would be my preferred option.
 

Design by Sue

Registered User.
Local time
Today, 03:54
Joined
Jul 16, 2010
Messages
640
darbid -will look into your code, thank you!
vbaInet Thank you for looking into this further. Your copy and paste seems to be what darbid's code is doing and the path to the image is where we started. Currently the images are in image controls. When we created this report, we looked into storing the OLE field idea and could not figure out how to make that process work. We were trying to not have any external files and keep all of the processes within Access. This thread is convincing me that is not an option.

Again thank you both, you have been helpful.

Sue
 

vbaInet

AWF VIP
Local time
Today, 10:54
Joined
Jan 22, 2010
Messages
26,374
Your copy and paste seems to be what darbid's code is doing and the path to the image is where we started.
Not quite darbid's code. An image control doesn't have a copy command like the chart example in Excel and a Shapes object in Word doesn't have a Picture property so you can't do:
Word.Shapes(0).Picture = Access.Image.Picture

We were trying to not have any external files and keep all of the processes within Access.

This thread is convincing me that is not an option.
You still need to save the image to disk (e.g. the temp folder) and add from disk. Once done, simply delete the image file on disk. Everything stays within Access!

The quickest way to save to disk would be to use an Attachment field to store the image. That field has a SaveToDisk method. Also try the method that spikepl showed.
 

darbid

Registered User.
Local time
Today, 11:54
Joined
Jun 26, 2008
Messages
1,428
You will find that vbaInet is right. I have just done a quick (really quick) google on how to get an image in Access into the clipboard to then use in word as I suggested.

I was surprised at the number of people with a similar question.

If you have the image as OLE then you can set focus and call a RunCommand acCmdCopy however you do not have an OLE object.

Thus if you want to keep what you have this appears to be the only solution I could find.
http://access.mvps.org/access/api/api0042.htm

My conclusion in your case is that maybe a temp file is the best and easiest way.
 

Users who are viewing this thread

Top Bottom