Microsoft Office Forums Using IncludePicture and MailMerge to insert picture

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #16  
Old 05-18-2016, 02:47 PM
macropod's Avatar
macropod macropod is offline Using IncludePicture and MailMerge to insert picture Windows 7 64bit Using IncludePicture and MailMerge to insert picture Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 19,525
macropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to behold
Default

Quote:
Originally Posted by StaplerGnome View Post
I don't suppose you know of any way to do this automatically, such as via a macro? There will be a lot of these letters to generate, and in particular my colleagues are going to struggle to remember to follow a hotkey routine.
Even a macro wouldn't make it automatic, since the users would still have to remember to run it.



That said, Word does have a 'MailMergeAfterMerge' class event that could be hooked into to make it automatic, but enabling the event is a fair bit of work to set up and requires the code to be added to the users' templates rather than to the mailmerge main document. For a basic outline, see: http://word.mvps.org/FAQs/MacrosVBA/AppClassEvents.htm
__________________
Cheers,
Paul Edstein
[MS MVP - Word]
Reply With Quote
  #17  
Old 05-23-2016, 06:21 PM
macropod's Avatar
macropod macropod is offline Using IncludePicture and MailMerge to insert picture Windows 7 64bit Using IncludePicture and MailMerge to insert picture Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 19,525
macropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to behold
Default

Here's a workaround to the linked image issue:

By adding the following macro to your mailmerge main document, clicking on the 'Edit Individual Documents' button will intercept the merge, finishing it and unlinking the pictures.
Code:
Sub MailMergeToDoc()
Application.ScreenUpdating = False
ActiveDocument.MailMerge.Execute
ActiveDocument.Fields.Unlink
Application.ScreenUpdating = True
End Sub
The only potential disadvantage of intercepting the 'Edit Individual Documents' process this way is that you no longer get to choose which records to merge at that stage. However, you can still achieve the same outcome - and with greater control - via the 'Edit Recipient List' tools.
__________________
Cheers,
Paul Edstein
[MS MVP - Word]
Reply With Quote
  #18  
Old 06-02-2016, 08:59 AM
StaplerGnome StaplerGnome is offline Using IncludePicture and MailMerge to insert picture Windows 7 64bit Using IncludePicture and MailMerge to insert picture Office 2010 64bit
Novice
 
Join Date: May 2016
Posts: 8
StaplerGnome is on a distinguished road
Default

Sorry to remain a pain. Unfortunately it isn't working - let me explain a bit more.

The way the documents are actually created is not from the Word doc. There's an Access database containing records. We create documents by selecting one of various buttons to generate the desired mail merged letter for that specific record.

I assume this is preventing your solution from doing anything by bypassing the way it gets triggered.

I've also tried the Unlink line in the main VBA code that runs the merge, but no joy (code line emphasised below):

Quote:
'this subroutine is what actually performs the mail merge
Sub RunMerge(docPath, docName)
Me.Refresh

'check whether the record is locked pending replacement examiners
If Me.checkReplacement = True Then
MsgBox ("Awaiting replacement examiners. Do not send thesis.")
Exit Sub
Else

Set oApp = CreateObject("Word.Application")

'this bit declares some variables used later
Dim oMainDoc As Word.Document
Dim oSel As Word.Selection
Dim sDBPath As String
Dim currentDbName As String
Dim selectSQL

Dim getDoc As String
getDoc = docPath & "\" & docName

' this specifies the location of the Word mail merge document we want to use
Set oMainDoc = oApp.Documents.Open(getDoc)
oApp.Visible = True

' this gets the file name and location of this Access database, used to provide data to the mail merge
' it's REALLY IMPORTANT TO NOTE that for inexplicable reasons, this only works with a .mdb file
' if you use an .accdb database, this stops working
' it will say it can't find the file FILEPATH.mdb, and strip out the filename and .accdb bit entirely
' I was unable to find ANY workarounds for this at all. Microsoft have just broken this functionality
' so use an .mdb
currentDbName = CurrentDb.Name

'this copies data from qryMain (where all our data is stored and combined) into the holding pen of tblMergeSource.
'Using a table as the mail merge data source is more stable than using a query
With DoCmd
.SetWarnings False
'clear the existing data
.RunSQL "DELETE FROM tblMergeSource"
'copy over the current record only - we only want to print letters for this student, not for everyone in the database!
'so copy records where the Reg No equals the Reg No currently displayed on the form you're looking at
.RunSQL "INSERT INTO tblMergeSource SELECT * FROM qryMain WHERE qryMain.[Registration No]='" & Me.[Registration No] & "'"
.SetWarnings True
End With

'this is the instruction we'll give to the mail merge in a minute, telling it to grab everything in tblMergeSource
selectSQL = "SELECT * FROM [tblMergeSource]"

'prepare a mail merge
With oMainDoc.mailMerge
.MainDocumentType = wdFormLetters
.OpenDataSource Name:=currentDbName, _
SQLStatement:=selectSQL
End With

'actually do the mail merge
With oMainDoc
'.MailMerge.Destination = wdSendToNewDocument
.mailMerge.Execute
.Fields.Unlink <<<<<<<<<<<<<<<<<<<it's here
End With

oMainDoc.Close (Word.WdSaveOptions.wdDoNotSaveChanges)
'move the focus to the Word document
oApp.Activate
oApp.Documents.Parent.Visible = True
oApp.Application.WindowState = 1
oApp.ActiveWindow.WindowState = 1

'RemovePicLinks (I also tested using a separate function, see below)

'clear various variables from memory to avoid strange crashing issues
Set oMainDoc = Nothing
Set oSel = Nothing

Set oApp = Nothing

End If

End Sub
In this case I call it twice and generate two documents with a single button.

I've tried a solution suggested elsewhere, of using a separate sub called by the main, but this only delinks the first document, presumably because of something about how it finds ActiveDocument.

Quote:
Public Sub RemovePicLinks()

Dim f As Word.Field
Dim i As Long
Dim lngCount As Long
Dim strMessage As String

For i = ActiveDocument.Fields.Count To 1 Step -1
Set f = ActiveDocument.Fields(i)
If f.Type = wdFieldIncludePicture Then
f.Unlink
lngCount = lngCount + 1
End If
Next i

If lngCount > 0 Then
strMessage = "Complete - " & CStr(lngCount) & " picture links were broken"
Else
strMessage = "Complete - no picture links were broken"
End If

MsgBox strMessage

End Sub
I suppose individual buttons for each document might work, but I'd really rather avoid having two dozen extra buttons on an already crowded UI to allow for every possible combination of letters that need making - and of course it greatly increases the risk of user error/omission.
Reply With Quote
  #19  
Old 06-02-2016, 02:40 PM
macropod's Avatar
macropod macropod is offline Using IncludePicture and MailMerge to insert picture Windows 7 64bit Using IncludePicture and MailMerge to insert picture Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 19,525
macropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to behold
Default

All you needed was:
oApp.ActiveDocument.Fields.Unlink
instead of:
.Fields.Unlink
__________________
Cheers,
Paul Edstein
[MS MVP - Word]
Reply With Quote
  #20  
Old 09-30-2018, 11:35 PM
krypticide krypticide is offline Using IncludePicture and MailMerge to insert picture Windows 10 Using IncludePicture and MailMerge to insert picture Office 2016
Novice
 
Join Date: Sep 2018
Posts: 1
krypticide is on a distinguished road
Default

Quote:
Originally Posted by macropod View Post
Hmm, it seems a Word update somewhere along the line has broken what was a perfectly good method for unlinking images during a mailmerge. Now all you get with that approach is linked images you can no longer access via any of the usual field methods. All is not lost, though. If you use the shorter version of the field:
{INCLUDEPICTURE {IF TRUE "C:\Users\Elena\Pictures\{MERGEFIELD Picture}"} \d}
you can still unlink the fields immediately after merging (e.g. via Ctrl-A, Ctrl-Shift-F9).
I've spent a few hours online looking up how to fix this, looks like it can't be done in Word 2016 any more. Thanks for the info.
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using IncludePicture and MailMerge to insert picture Insert Picture changes colors rowan.bradley Drawing and Graphics 6 05-18-2013 05:26 PM
Using IncludePicture and MailMerge to insert picture Macro to insert picture in footer Sharon Word 5 01-29-2013 03:12 AM
Using IncludePicture and MailMerge to insert picture insert picture file location gary1 Word 9 12-16-2012 04:37 PM
Using IncludePicture and MailMerge to insert picture Macro for Picture Insert rfhall50 Word VBA 2 10-25-2010 12:41 PM
Using IncludePicture and MailMerge to insert picture Can I insert a picture into a picture ? alexcalgary Drawing and Graphics 2 10-16-2010 03:29 PM


All times are GMT -7. The time now is 11:47 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2019, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2019 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft