Cross post- Now trying Access

Ricky

Registered User.
Local time
Today, 15:45
Joined
May 30, 2000
Messages
13
Hi all. Cross post as I cant seem to find any assistance with Word. I have a customer requestion a mail merge to their customers. They would like to include their sales reps signature at the bottom of the letter. The signatures have been scanned. So the merge would contain a customer letter with varible signatures based on rep name. I have a table created with the customer name address, city state and zip as well as applicable rep name. I also set up a field for signatures with \\server\location\name.jpg links but can not find a way to merge these jpgs in with my form. Any ideas?
TIA
 
Here is how I solved the same problem in Word '97

I just had to have a laugh at myself, because I thought your post was recent; turns out on closer inspection it is a couple of years old!!! I came up with this solution (to my Father's problem) in SEP 2002.

Hopefully you've solved your problem long ago, but I will continue to post this, in case it is useful to a forum searcher in the future :) .

--------------------

In a dedicated folder, I stored the signature bitmaps, and an ini file to correlate the bmp file names with the Staff Member names.

In the word mail merge document, I embedded the Staff Member name (to be replaced with signature image) inside a designed marker string. For courtesy, the name is also mail merged to below where the signature will (eventually) appear e.g:-

[==insert.signature.file.«StaffName»==]
«StaffName»

Then I performed the mail merge, and ran the following (word VBA) macro (AddSignatureGraphics). Explanations are included in comments.

Code:
Private Const SIG_PATH = "C:\SIGNATURES\"
Private Const SIG_INI = "SIG.INI"
Private Const SEARCH_FOR = "[==insert.signature.file."
Private Const SEARCH_END = "==]"


Public Sub AddSignatureGraphics()
    
    'enable error handler
    On Error GoTo AddSignatureGraphics_err
    
    'declare some object variables
    Dim docADocument As Document
    Dim rngSearchForFound As Range
    Dim rngSearchEndFound As Range
    Dim rngSignatoryName As Range
    Dim rngReplace As Range
    
    'Declare some String Variables
    Dim szSignatory As String
    Dim szSigFileName As String
    
    'Iterate through each open document
    For Each docADocument In Word.Documents
    
        'set each range to some arbitrary range,
        'we will make adjustments later
        Set rngSearchForFound = docADocument.Content
        Set rngSearchEndFound = docADocument.Content
        Set rngReplace = docADocument.Content
        Set rngSignatoryName = docADocument.Content
        
        'look for the SEARCH_FOR text
        rngSearchForFound.Find.Execute findtext:=SEARCH_FOR, Forward:=True
        
        'if we found the SEARCH_FOR text
        Do While rngSearchForFound.Find.Found = True
        
            'set the starting point for looking for the SEARCH_END text
            'to the place we found the SEARCH_FOR text
            rngSearchEndFound.Start = rngSearchForFound.Start
            
            'look for the SEARCH_END text
            rngSearchEndFound.Find.Execute findtext:=SEARCH_END, Forward:=True
            
            If rngSearchEndFound.Find.Found = True Then
                'we found the SEARCH_END text
                
                'test to make sure it is in the same paragraph as the SEARCH_FOR text,
                'if it is not, then we are not interested in it.
                If rngSearchEndFound.InRange(rngSearchForFound.Paragraphs(1).Range) Then
                    
                    'we are interested.
                    
                    're-define the start and end positions of the range
                    'to be replaced, based (respectively) on the start
                    'and end positions of the SEARCH_FOR and
                    'SEARCH_END text which we found
                    rngReplace.Start = rngSearchForFound.Start
                    rngReplace.End = rngSearchEndFound.End
                    
                    're-define the start and end positions of the range
                    'where we expect to find the signatory's name,
                    'based (respectively) on the end
                    'and start positions of the SEARCH_FOR and
                    'SEARCH_END text which we found
                    rngSignatoryName.Start = rngSearchForFound.End
                    rngSignatoryName.End = rngSearchEndFound.Start
                    
                    'grab the name of the signatory
                    szSignatory = Trim(rngSignatoryName.Text)
                    
                    'look up the corresponding file name for the
                    'signature file
                    szSigFileName = szSignatoryNameToFileName(szSignatory)
                    
                    'Ensure we got a good result (i.e. a filename)
                    If Len(szSigFileName) Then
                        'delete the place marker
                        rngReplace.Delete
                        
                        'insert the signature file
                        rngReplace.InlineShapes.AddPicture FileName:=szEnsureTrailingBackSlashOnPath(SIG_PATH) & szSigFileName, _
                        LinkToFile:=False, SaveWithDocument:=True
                    End If   ' got a file name
                    
                End If   'SEARCH_FOR and SEARCH_END markers found were both within the same paragraph
                
            End If   'SEARCH_END marker found
            
            'redefine the starting position for looking for the next SEARCH_FOR marker
            rngSearchForFound.Collapse wdCollapseEnd
            
            'look for the next SEARCH_FOR marker
            rngSearchForFound.Find.Execute findtext:=SEARCH_FOR, Forward:=True
        
        Loop   'see if we found one
        
    Next docADocument
    
AddSignatureGraphics_exit:
    Set docADocument = Nothing
    Set rngSearchForFound = Nothing
    Set rngSearchEndFound = Nothing
    Set rngReplace = Nothing
    Set rngSignatoryName = Nothing
    
    Exit Sub
    
AddSignatureGraphics_err:
    MsgBox "An error occurred in attempting to add the signatures." & vbCrLf & vbCrLf _
    & "Error Number : " & Err.Number & vbCrLf _
    & "Error Description : " & Err.Description, vbExclamation + vbOKOnly, "Error Adding Signatures", Err.HelpFile, Err.HelpContext
    Resume AddSignatureGraphics_exit
End Sub


Private Function szEnsureTrailingBackSlashOnPath(ByVal szPath As String) As String
    On Error Resume Next
    If Len(szPath) > 0 Then
        If Right(szPath, 1) <> "\" Then
            szPath = szPath & "\"
        End If
    End If
    szEnsureTrailingBackSlashOnPath = szPath
End Function

Private Function szSignatoryNameToFileName(szSignatory As String) As String
    szSignatoryNameToFileName = System.PrivateProfileString(szEnsureTrailingBackSlashOnPath(SIG_PATH) & SIG_INI, "SignatureFiles", szSignatory)
End Function

The SIG.INI file looked like this:-
Code:
[SignatureFiles]
JOHN CITIZEN = JOHN.BMP
SHARON SHARPSHOT = SHARON.BMP

And the SIGNATURES directory therefore had files named JOHN.BMP and SHARON.BMP etc

HTH (belated!!!!)

John.
 

Users who are viewing this thread

Back
Top Bottom