Microsoft Office Forums

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: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
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
[Fmr 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: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
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
[Fmr 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: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

All you needed was:
oApp.ActiveDocument.Fields.Unlink
instead of:
.Fields.Unlink
__________________
Cheers,
Paul Edstein
[Fmr 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
  #21  
Old 05-29-2020, 06:41 AM
rUZZ2K rUZZ2K is offline Using IncludePicture and MailMerge to insert picture Windows 10 Using IncludePicture and MailMerge to insert picture Office 2019
Novice
 
Join Date: May 2020
Posts: 1
rUZZ2K is on a distinguished road
Default How to name path differently for includepicture field codes

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 have an amended version of this so it has .jpg separately so the spreadsheet only has the file name, the files are named 2,3,4,5 which works fine but also 2.5,3.5 and 4.5 which do not load probably because of it not translating the path correctly, they are all .jpg so 2.5 would be 2.5.jpg which i think is where the problem lies.

can anyone help for me to get this right. much appreciated.
Reply With Quote
  #22  
Old 05-29-2020, 02:51 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: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Quote:
Originally Posted by rUZZ2K View Post
I have an amended version of this so it has .jpg separately so the spreadsheet only has the file name, the files are named 2,3,4,5 which works fine but also 2.5,3.5 and 4.5 which do not load probably because of it not translating the path correctly
If the merge works correctly for the images whose names are whole numbers, the issue is unlikely to be anything to do with the path. That said, when the merge is done as per Managing Mailmerge Graphics in the Mailmerge Tips & Tricks 'Sticky' thread at the top of this forum (https://www.msofficeforums.com/mail-...ps-tricks.html), everything works just fine.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #23  
Old 06-20-2020, 10:01 AM
faisal.iftikhar985 faisal.iftikhar985 is offline Using IncludePicture and MailMerge to insert picture Windows 10 Using IncludePicture and MailMerge to insert picture Office 2016
Novice
 
Join Date: Jun 2020
Location: Rawalpindi
Posts: 1
faisal.iftikhar985 is on a distinguished road
Default

Dear,

I have tried one of the option mentioned above but with no luck as I still have to refresh the fields (eg Ctrl-A, then F9) to display the Images. The Path of the Image is included in the data field coming from excel.

Here is the syntax I follow:
{IF {INCLUDEPICTURE {IF TRUE «Picture»} \d} {INCLUDEPICTURE {IF TRUE «Picture»} \d}}

Thank you in advance.
Reply With Quote
  #24  
Old 06-20-2020, 04:29 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: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Kindly read the material in the link referred to in post #22.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #25  
Old 02-04-2022, 02:06 PM
ffmcorrea2 ffmcorrea2 is offline Using IncludePicture and MailMerge to insert picture Windows 10 Using IncludePicture and MailMerge to insert picture Office 2010
Novice
 
Join Date: Feb 2022
Posts: 1
ffmcorrea2 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).
Hey there! In this example "Picture" is the name of the file? Do I need to put the extension too like "Picture.jpg"?
I attached a screenshot of my Word document. Is that correct?
Attached Images
File Type: png test.PNG (12.5 KB, 17 views)

Last edited by ffmcorrea2; 02-04-2022 at 02:09 PM. Reason: including a screenshot
Reply With Quote
  #26  
Old 02-06-2022, 05:35 PM
macropod's Avatar
macropod macropod is offline Using IncludePicture and MailMerge to insert picture Windows 10 Using IncludePicture and MailMerge to insert picture Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

For example: {INCLUDEPICTURE {IF TRUE "C:\fotos\{MERGEFIELD Picture}.jpeg"} \d}
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
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

Other Forums: Access Forums

All times are GMT -7. The time now is 01:54 AM.


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