Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Word mail merge - emailing drops footer

Status
Not open for further replies.

Bluejay07

Programmer
Mar 9, 2007
780
CA
Hello,

I have code that creates a mail merge (testing in Word 2007).
The code verifies the datasource for an email address and if it has one, then the document is emailed.

All functionality for the mail merge seems to work.
The problem is that when the email is performed, the page footer is dropped and is not included in the email.
Even when trying the mail merge emailing function manually, the footer still isn't included.

The logo, text and textboxes are all included.

Any suggestions on what I can do so that the footer is included with the document when emailing?

Thanks.

If at first you don't succeed, then sky diving wasn't meant for you!
 
hi,

Even when trying the mail merge emailing function manually, the footer still isn't included.

Then this is NOT a VBA issue!

Forum68.

Skip,

[glasses]Just traded in my OLD subtlety...
for a NUance![tongue]
 
Hi skip,

If I need to add or do something differently in the mail merge code then it could be a VBA issue.
I'll cross post in the other forum as well.

If at first you don't succeed, then sky diving wasn't meant for you!
 
Generally, if you can't do something in the native application, then you won't be able to do that something in the application VBA either.

Skip,

[glasses]Just traded in my OLD subtlety...
for a NUance![tongue]
 
Since emails don't have a 'page' as such, there's nowhere for the footer to go. Accordingly, if you want all of your message to go as the body of the email, you'll need to add code to extract the footer and write it to a suitable location in the email. Alternatively, you could send the document an attachment.

Cheers
Paul Edstein
[MS MVP - Word]
 
Hi Skip,

Generally speaking your comment is true although there are many cases where programmers have found a solution to perform some action where it otherwise would not be possible to do.

Hi macropod,

Thanks for the reply. Do you know of any code to extract the footer text?
Doing a search I came across the following although there may be better methods:
Code:
ActiveDocument.Sections(1).Footers(wdHeaderFooterPrimary).Range.Text

Testing the above code in the immediate window does provide the entire footer text, although it also adds a few extra blank lines and two lines with only bullet markers.

In addition, in this case I want the mail merge document to be the email message (due to the nature of the message) since an attachment would most likely not get noticed.

Using the code below, how would I add text to the bottom of the email message?
Code:
    Windows(DocName).Activate
    
    ' Do mailmerge
    ' Only send if an email address exists.
    With ActiveDocument.MailMerge
        .MainDocumentType = wdEMail

        'Specify the data source here
        .OpenDataSource Name:=strDataSource & "\" & DocNameCut & ".dbf", _
            ConfirmConversions:=False, ReadOnly:=False, LinkToSource:=True, _
            AddToRecentFiles:=False, PasswordDocument:="", PasswordTemplate:="", _
            WritePasswordDocument:="", WritePasswordTemplate:="", Revert:=False, _
            Format:=wdOpenFormatAuto, Connection:= _
            "Provider=Microsoft.ACE.OLEDB.12.0;User ID=Admin;Data Source=" & strDataSource & ";" & _
            "Mode=Read;Extended Properties="""";Jet OLEDB:System database="""";Jet OLEDB:Registry Path="""";" & _
            "Jet OLEDB:Engine Type=18;Jet OLEDB:Database Locking Mode=0;Jet OLEDB:Global Partial Bulk Ops=" _
            , SQLStatement:="SELECT * FROM `" & DocNameCut & "` WHERE EMAIL > ''", SQLStatement1:="", SubType:=wdMergeSubTypeAccess
            
        If .DataSource.RecordCount > 0 Then

            .MailSubject = "Notice RE: " & .DataSource.DataFields("CLIENT").Value
            .MailFormat = wdMailFormatHTML
            .Destination = wdSendToEmail
            .MailAddressFieldName = "EMAIL"
            .SuppressBlankLines = True
            
            With .DataSource
                 .MappedDataFields(wdFirstName).DataFieldIndex = .DataFields("DFNAME").Index
                 .MappedDataFields(wdLastName).DataFieldIndex = .DataFields("DLNAME").Index
                 .MappedDataFields(wdUniqueIdentifier).DataFieldIndex = .DataFields("CUSTNUM").Index
                 .MappedDataFields(wdAddress1).DataFieldIndex = .DataFields("DADDR1").Index
                 .MappedDataFields(wdCity).DataFieldIndex = .DataFields("DCITY").Index
                 .MappedDataFields(wdState).DataFieldIndex = .DataFields("DPROV").Index
                 .MappedDataFields(wdPostalCode).DataFieldIndex = .DataFields("DPCODE").Index
                 .MappedDataFields(wdCountryRegion).DataFieldIndex = .DataFields("DCOUNTRY").Index
                 .MappedDataFields(wdEmailAddress).DataFieldIndex = .DataFields("EMAIL").Index
                 .MappedDataFields(wdSpouseFirstName).DataFieldIndex = .DataFields("SPOUSEFNAM").Index
                 .MappedDataFields(wdSpouseLastName).DataFieldIndex = .DataFields("SPOUSELNAM").Index
                 .FirstRecord = wdDefaultFirstRecord
                 .LastRecord = wdDefaultLastRecord
             End With
             .Execute Pause:=False
        End If
    End With

Thanks.

If at first you don't succeed, then sky diving wasn't meant for you!
 

Using the code below, how would I add text to the bottom of the email message?

I'd put it at the end of this block
Code:
If .DataSource.RecordCount > 0 Then

....
   ActiveDocument.Sections(1).Footers(wdHeaderFooterPrimary).Range.Text 
End If

But I'm not sure what you are assigning the data any of your code to???  It's just hanging there in the Word document.  Where's the MailItem?

Skip,
[sub]
[glasses]Just traded in my [b]OLD subtlety[/b]...
for a [b]NUance![/b][tongue][/sub]
 
With this syntax, I do not need the MailItem object.
You should also notice that I do not have access to the traditional mail components such as To, CC, BCC, Body.

I can certainly place the footer text in that section of code but what does it get assigned to so that it's included in the email body?

As a side note, Skip, you and I were discussing other related issues when I first started this merge several months ago in thread707-1714151.


If at first you don't succeed, then sky diving wasn't meant for you!
 

So is this basic issue that when you do your mailmerge, there may be an indeterminate number of Word pages, so you cannot predetermine where the end of the document is prior to run time? YES?

Otherwise, pull the text out of the footer and stick it at the end of the document.

Skip,

[glasses]Just traded in my OLD subtlety...
for a NUance![tongue]
 
Hi Bluejay07,
Testing the above code in the immediate window does provide the entire footer text, although it also adds a few extra blank lines and two lines with only bullet markers.
Any extra lines are because they're already in either the document, the footer or your email body.
In addition, in this case I want the mail merge document to be the email message (due to the nature of the message) since an attachment would most likely not get noticed.
Surely dealing with that is just a matter of drawing attention to the attachment in the email body...

Cheers
Paul Edstein
[MS MVP - Word]
 
Hi Skip,

You are correct in that there will be an indeterminate number of Word pages.
I would not want the footer information at the end of the document, just at the end of each 'page'.

In addition, I can't just pull the footer information and stick it at the end of the document. It has to be assigned to something otherwise it errors out when the procedure is called.


Hi macropod,

I did check for extra lines and removed them. It didn't seem to make any difference.
It also doesn't explain the two bulleted lines.

In addition, calling attention to the attachment wouldn't work. The merged messages are debt collection notices and need to be seen, not 'hidden' (for a want of a better word).


With the responses I've seen, it really doesn't seem possible to include the footer information in the mail merge format that I am using.
I think the only option is to add a textbox filled with the footer information and place it near the bottom of the mail merge page.

Thanks for all the responses.

If at first you don't succeed, then sky diving wasn't meant for you!
 
I did check for extra lines and removed them. It didn't seem to make any difference.
It also doesn't explain the two bulleted lines.
Without seeing your code and the document you're processing I can't really comment on either issue except to say that inserting header/footer content does not of itself cause either occurrence.

I'd be surprised if merely adding textboxes to the mailmerge resolves the issue.

Cheers
Paul Edstein
[MS MVP - Word]
 
Hi Paul,

Adding the textbox worked out.
I adjusted the vertical alignment position and set it to the bottom relative to the page.

This way it looks like a page footer but isn't a page footer.
It appears on the mail merge and the email message perfectly.

Thanks for the help and opinions.

If at first you don't succeed, then sky diving wasn't meant for you!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top