Mail merge to Fax from Word 2003 : formatting lost !

R

Raphaël Vanney

Hello there !

I have this interesting (to me) problem that's driving me completely nuts.
If I had had less hair to start with, I might be hairless now.
Anyways.
I am trying to fax a document to several (300) recipients. My document is a
reasonably simple text, with two pictures (cliparts) in it. The recipients
are listed in an Excel document.
I use the mail merge to e-mail feature, since merging directly to fax is no
longer available.
All goes pretty well till the end of the wisard. I am then asked what format
I should use for the document.
If I choose "HTML", my single-page document ends up taking four pages when
faxed : first page holds the address block, second one the text part of my
document, third and fourth the two cliparts of my document, zoomed so as to
take a whole page each.
If I choose "text" or "attachment", Word hangs at the second record. Weirdly
enough, I also get a request from Outlook to confirm that Word should access
my contact list (I fail to see what for), and another one to confirm that
Word can send mail on my behalf. Funny I don't get these confirmation
screens with the HTML format.
This is using Word 2003 (Office 2003) on XP Pro.

Help !!!

R.
 
P

Peter Jamieson

I have this interesting (to me) problem that's driving me completely nuts.

Believe me, you are not alone.
I use the mail merge to e-mail feature, since merging directly to fax is no
longer available.

As far as I can tell, it is, probably. However, I had difficulty making it
work and am not sure what I did will work for you.

Assuming you want to use a FaxModem attached directly to your PC, the
necessary conditions seem to be that
a. you have installed the Windows XP Fax service software. I think that now
happens by default, but if not you can do it from Control Panel|Add or
Remove Programs|Add/Remove Windows Components.
b. you have added the Fax service to your Outlook Profile. These days you
probably need to do that in Outlook|Tools|Options|Mail Setup|E-mail
Accounts|E-mail - View or change existing e-mail accounts|Add|Additional
Server types|Fax Mail Transport. Then select it in the list of "e-mail"
accounts and click Change to set up the properties.
c. your fax numbers (in your Excel spreadsheet) are in the format

[FAX:0123456789]

(i.e. open square bracket, "FAX:", the number, close square bracket

d. You have a file called msmail.ini in your Windows directory (or WINNT
directory or whatever) with at least the following lines:

[EFAX Transport]
LocalFax=1

e. the file win.ini in the Windows directory has at least the following
lines:

[Mail]
MAPI=1
MAPIX=1

You may also need

CMC=1
CMCDLLNAME=mapi.dll
CMCDLLNAME32=mapi32.dll
MAPIXVER=1.0.0.1
OLEMessaging=1

but I don't think they are essential.

(a) and (b) essentially enable the fax service and make it available, (d)
and (e) enable the relevant buttons/optoins in Word mailmerge, and (c) makes
the MAPI spooler which Word sends its output to recognise which transport to
send the messages to.

If you do attempt this and manage to make it work, please post back here.
 
R

Raphaël Vanney

Hi Peter.

First off, let me thank you for a most comprehensive and knowledgeable
answer. I appreciate it.
I applied your suggestion ; the only missing thing in my case was the file
you mention in (d). What this changed is that I now have the "Merge to fax"
button enabled in the mail merge toolbar: so I guess we can call it a
success so far !

However, when I perform a mail merge to the fax, what happens is... Word
transfers the faxes to Outlook, which sends them to MS Fax... As opposed to
what happens when doing a File/Send to/Fax in Word, where Word sends the
document directly to MS Fax.
Needless to say, in the mail merge situation, the formatting is lost
somewhere between Outlook and MS Fax (when I check the documents in
Outlook's Outbox, it's still looking okay).

Bummer...?

I tried to see if I could spot anything in Outlook's configuration that
could explain this, but apparently there's nothing...

Argh !

R.


Peter Jamieson said:
I have this interesting (to me) problem that's driving me completely
nuts.

Believe me, you are not alone.
I use the mail merge to e-mail feature, since merging directly to fax is no
longer available.

As far as I can tell, it is, probably. However, I had difficulty making it
work and am not sure what I did will work for you.

Assuming you want to use a FaxModem attached directly to your PC, the
necessary conditions seem to be that
a. you have installed the Windows XP Fax service software. I think that now
happens by default, but if not you can do it from Control Panel|Add or
Remove Programs|Add/Remove Windows Components.
b. you have added the Fax service to your Outlook Profile. These days you
probably need to do that in Outlook|Tools|Options|Mail Setup|E-mail
Accounts|E-mail - View or change existing e-mail accounts|Add|Additional
Server types|Fax Mail Transport. Then select it in the list of "e-mail"
accounts and click Change to set up the properties.
c. your fax numbers (in your Excel spreadsheet) are in the format

[FAX:0123456789]

(i.e. open square bracket, "FAX:", the number, close square bracket

d. You have a file called msmail.ini in your Windows directory (or WINNT
directory or whatever) with at least the following lines:

[EFAX Transport]
LocalFax=1

e. the file win.ini in the Windows directory has at least the following
lines:

[Mail]
MAPI=1
MAPIX=1

You may also need

CMC=1
CMCDLLNAME=mapi.dll
CMCDLLNAME32=mapi32.dll
MAPIXVER=1.0.0.1
OLEMessaging=1

but I don't think they are essential.

(a) and (b) essentially enable the fax service and make it available, (d)
and (e) enable the relevant buttons/optoins in Word mailmerge, and (c) makes
the MAPI spooler which Word sends its output to recognise which transport to
send the messages to.

If you do attempt this and manage to make it work, please post back here.
 
P

Peter Jamieson

OK, I realised I didn't test the "image" part of your merge and when I did
that I had a similar result to the one you reported - whatever I do the
image is shifted to a new page and fills that page. The simple text
formatting I used in testing does, however, survive.

I'm currently asking around on this one, and have one or two more ideas, but
they will take some time to work through and may come to nothing.

--
Peter Jamieson - Word MVP

Raphaël Vanney said:
Hi Peter.

First off, let me thank you for a most comprehensive and knowledgeable
answer. I appreciate it.
I applied your suggestion ; the only missing thing in my case was the file
you mention in (d). What this changed is that I now have the "Merge to fax"
button enabled in the mail merge toolbar: so I guess we can call it a
success so far !

However, when I perform a mail merge to the fax, what happens is... Word
transfers the faxes to Outlook, which sends them to MS Fax... As opposed to
what happens when doing a File/Send to/Fax in Word, where Word sends the
document directly to MS Fax.
Needless to say, in the mail merge situation, the formatting is lost
somewhere between Outlook and MS Fax (when I check the documents in
Outlook's Outbox, it's still looking okay).

Bummer...?

I tried to see if I could spot anything in Outlook's configuration that
could explain this, but apparently there's nothing...

Argh !

R.


Peter Jamieson said:
nuts.

Believe me, you are not alone.
is
no
longer available.

As far as I can tell, it is, probably. However, I had difficulty making it
work and am not sure what I did will work for you.

Assuming you want to use a FaxModem attached directly to your PC, the
necessary conditions seem to be that
a. you have installed the Windows XP Fax service software. I think that now
happens by default, but if not you can do it from Control Panel|Add or
Remove Programs|Add/Remove Windows Components.
b. you have added the Fax service to your Outlook Profile. These days you
probably need to do that in Outlook|Tools|Options|Mail Setup|E-mail
Accounts|E-mail - View or change existing e-mail accounts|Add|Additional
Server types|Fax Mail Transport. Then select it in the list of "e-mail"
accounts and click Change to set up the properties.
c. your fax numbers (in your Excel spreadsheet) are in the format

[FAX:0123456789]

(i.e. open square bracket, "FAX:", the number, close square bracket

d. You have a file called msmail.ini in your Windows directory (or WINNT
directory or whatever) with at least the following lines:

[EFAX Transport]
LocalFax=1

e. the file win.ini in the Windows directory has at least the following
lines:

[Mail]
MAPI=1
MAPIX=1

You may also need

CMC=1
CMCDLLNAME=mapi.dll
CMCDLLNAME32=mapi32.dll
MAPIXVER=1.0.0.1
OLEMessaging=1

but I don't think they are essential.

(a) and (b) essentially enable the fax service and make it available, (d)
and (e) enable the relevant buttons/optoins in Word mailmerge, and (c) makes
the MAPI spooler which Word sends its output to recognise which
transport
to
send the messages to.

If you do attempt this and manage to make it work, please post back
here.
 
P

Peter Jamieson

but
they will take some time to work through

It took a while, but if you are still interested...

First, it turns out that the merge-to-fax approach we tried (which has to go
via Outlook) has never worked properly in Win2k and later where the document
contained images. As far as I can tell this must result from a problem in
the way that Outlook renders message content when it "prints" fax messages
to the fax printer/service.

Second, I do not know if you tried using the mail to Internet Fax service
feature in Word 2003 (e.g. signing up with Venali), or whether you really
prefer to send your faxes directly using your faxmodem. The trouble is that
as things stand, neither approach works as it stands with a merge. If you
want to use the former, I have a sequence of instructions from Russ
Valentine that may work. If you prefer to use your own faxmodem, I've
developed the following Word VBA macro, which seems to work OK here and has
the advantage of bypassing Outlook altogether.

If you're going to try it, please read the notes, modify the macro to suit
your needs, and test it (I have done a certain amount of testing here and it
seems to work with single- and multi-page documents with text and images,
with and without cover pages, but I have not done an awful lot of testing.
FWIW I've tested with Word 2000 SP2 on WIn2K and Word 2003 on WinXP but not
Word 2002). I would be interested in any feedback you may have, either in
here or despam my address and e-mail me.

If you're unfamiliar with VBA etc. getting this to work could be quite
difficult. A useful starting point is the Word MVPs site at
http://www.mvps.org/word , and specifically the following "get-you-started"
article

http://www.mvps.org/word/FAQs/MacrosVBA/CreateAMacro.htm

Also, please note that I am likely to be "off-air" for the next few days so
may not be able to respond quickly to any questions.

The macro code:

'-----------------------------------------------------
Sub MergeOneFaxPerSourceRec()

' Disclaimer: Use this macro at your own risk.
' Purpose: Perform one Word mailmerge for each record in
' a Word data source, sending the results of each
' merge to a different fax number specified in a
' column of the data source
' Author: Peter J Jamieson
' Date: November 2003
' Assumes: Word 2000 or later (Word 97 might work)
' Windows 2000 or later, with the standard
' fax service software installed and
' configured to use a working fax device
' You have used Tools|References in the VBA
' editor to add the appropriate type library
' ("Faxcom 1.0 Type Library")
' You correctly adapt the macro to your
' environment
' Overview: The routine performs one merge per record
' in the data source. For each merge, the macro:
' - creates a new Word document
' - "prints" the document to the Fax printer,
' but outputting the result to a .tif file
' rather than allowing the fax printer to
' send the fax directly. This allows us to
' specify the fax number etc. in the macro
' rather than having to respond to the fax
' printer's dialog box.
' - submits the tif file to the fax service
' - discards the Word document
'
' Notes: This does not use the Extended Fax client API
' because it is not available in Windows 2000.
'
' This macro relies on the fax service to deliver
' the faxes once trhey have been submitted. You
' should use the fax service to verify which faxes
' have been sent and which, if any, failed. The fax
' service should retain a copy of each fax submitted
' so that retransmission should be feasible from
' within the service, i.e. without re-running the
' merge.

' NB, needs bettor error management and doubtless other
' things a VBA expert would point out.

' Specify the path for the .tif files saved by the Fax Printer
' This path must exist and the name should end with "\"
Const sTifFolder = "c:\tif\"
' Specify the name of the .tif file to output
Const sTifFile = "mergetif.tif"
' Specify the fax printer name that makes it all work
Const sFaxPrinter = "Fax"

Dim bFaxPortAvailable As Boolean
Dim bFaxServerAvailable As Boolean

Dim bTerminateMerge As Boolean

Dim lJobID As Long
Dim lSourceRecord As Long

Dim oApp As Word.Application
Dim oDataFields As Word.MailMergeDataFields
Dim oDoc As Word.Document
Dim oFaxDoc As FAXCOMLib.FaxDoc
Dim oFaxPort As FAXCOMLib.FaxPort
Dim oFaxPorts As FAXCOMLib.FaxPorts
Dim oFaxServer As FAXCOMLib.FaxServer
Dim oMerge As Word.MailMerge

Dim sActivePrinter As String
Dim sTifPath As String

' Phase 1.
' Connect to the Fax server
' and optionally see if a Port is available

Set oFaxServer = CreateObject("FaxServer.FaxServer")

If oFaxServer Is Nothing Then
MsgBox "Could not create a fax server object"
bFaxServerAvailable = False
Else
' This should connect us to the fax server on the current machine
oFaxServer.Connect Servername:=Environ("computername")
bFaxServerAvailable = True
bFaxPortAvailable = True

' begin optional section
' - ensure that at least one output port is available
' - not essential but we will just see an error later
' if no output port is available
Set oFaxPorts = oFaxServer.GetPorts
If oFaxPorts.Count = 0 Then
MsgBox "The fax server has no fax devices"
bFaxPortAvailable = False
Else
' look for a port that can send
For i = 1 To oFaxPorts.Count
Set oFaxPort = oFaxPorts.Item(i)
If oFaxPort.Send = 0 Then
Set oFaxPort = Nothing
Else
Exit For
End If
Next
If oFaxPort Is Nothing Then
MsgBox "The fax server has no ports configured to send faxes"
bFaxPortAvailable = False
Else
' at the moment we do not use the FaxPort object to get status
' info. so just get rid of it
Set oFaxPort = Nothing
End If
End If
' we do not need this either
Set oFaxPorts = Nothing
' end optional section

End If

' Phase 2.
' We can fax, so set up the printer
' and start the merges.

If bFaxServerAvailable And bFaxPortAvailable Then

' You may need to change this
Set oApp = Application

' The mail merge main document is assumed
' to be the active document in the current
' instance of Word
Set oDoc = oApp.ActiveDocument
Set oMerge = oDoc.MailMerge
Set oDataFields = oMerge.DataSource.DataFields

' save and set up the active printer
sActivePrinter = oApp.ActivePrinter
' don't change the printer if it is already
' correctly set up
' (I had problems when I tried to switch
' to the fax printer in code)
' you may need to adjust this for your
' fax printer name
If Left(sActivePrinter, 3) <> sFaxPrinter Then
oApp.ActivePrinter = sFaxPrinter
End If

With oMerge

' If no data source has been defined,
' do it here using OpenDataSource.
' But if it is already defined in the document,
' you should not need to define it here.

' .OpenDataSource _
' Name:="whatever"

lSourceRecord = 1
bTerminateMerge = False

Do Until bTerminateMerge
.DataSource.ActiveRecord = lSourceRecord

' if we have gone past the end
' (and possibly, if there are no records)
' then the Activerecord will not be what
' we have just tried to set it to

If .DataSource.ActiveRecord <> lSourceRecord Then
bTerminateMerge = True
Else
.DataSource.FirstRecord = lSourceRecord
.DataSource.LastRecord = lSourceRecord
.Destination = wdSendToNewDocument
.Execute

' Word always sets the output document produced
' by the merge to be the ActiveDocument

' Now print to the fax printer, specifying an
' OutputFileName.
' Specifying Background:=False is
' particularly important or the fax stage
' will fail later

' create the full path name for the file.
' (done separately so you can change the way
' you create the name and re-use the name later)

sTifPath = sTifFolder + sTifFile
oApp.PrintOut _
Background:=False, _
Append:=False, _
Range:=wdPrintAllDocument, _
OutputFileName:=sTifPath, _
Item:=wdPrintDocumentContent, _
Copies:=1, _
PageType:=wdPrintAllPages, _
PrintToFile:=True

'Don't need the document any more
oApp.ActiveDocument.Close Savechanges:=False

' Now make a FaxDocument
Set oFaxDoc = oFaxServer.CreateDocument(sTifPath)
If oFaxDoc Is Nothing Then
MsgBox "Could not create the fax document"
' you could consider finishing here by setting
' TerminateMerge = True
Else
' fill in whatever details you need
' from the data source or elsewhere
With oFaxDoc
' The number to send to. The only really essential
' piece of information. Here we get it from
' a field in the data source called "faxnumber"
.FaxNumber = oDataFields("faxnumber")

' DisplayName is a "user-friendly" name used
' by the Fax Server when you e.g. inspect the
' current fax status

' here we get it from a field in the data source
' called ufname
.DisplayName = oDataFields("ufname")
' here we just set it to ""
'.DisplayName = ""

' If you want a cover page, set SendCoverPage
' to a nonzero value. You could define whether
' or not you want a cover page, and which
' page to use, in your data source. However,
' if you specify a cover page, you /must/
' provide a valid name for the page. This code
' does not verify whether you do or not.
.SendCoverpage = 0

' If the cover page (.cov file) is a common
' cover page located on the server (i.e. in the
' default folder), set ServerCoverPage=-1
' and provide the name of the cover page
' If the cover page is somewhere else,
' set ServerCoverPage=0 and specify the
' full path name of the cover page
.ServerCoverpage = 1
.CoverpageName = ""

' The following items may be used in the coverpage
' or they may be displayed in fax service status
' dialog boxes. The items visible in the Win2000
' fax status are indicated by
'** displayed in dialog

.CoverpageNote = ""
.CoverpageSubject = ""
.EmailAddress = ""
.RecipientAddress = ""
.RecipientCity = ""
.RecipientCompany = ""
.RecipientCountry = ""
.RecipientDepartment = ""
.RecipientHomePhone = ""
'** displayed in dialog
.RecipientName = ""
.RecipientOffice = ""
.RecipientOfficePhone = ""
.RecipientState = ""
.RecipientTitle = ""
.RecipientZip = ""
.SenderAddress = ""
'** displayed in dialog
.SenderCompany = ""
'** displayed in dialog
.SenderDepartment = ""
.SenderFax = ""
.SenderHomePhone = ""
'** displayed in dialog
.SenderName = ""
.SenderOffice = ""
.SenderOfficePhone = ""
.SenderTitle = ""

'** displayed in dialog
.BillingCode = ""

' DiscountSend = 0 means "send immediately
' If you have set up discount periods, setting
' DiscountSend to a nonzero value will make the
' fax service send in a discount period
.DiscountSend = 0

' In theory, the TSID is the Fax sender ID printed
' on the fax, i.e. typically your contact fax number,
' but the value set up in the fax service appears to
' override any value set here.
'.Tsid = ""
End With

' Now send the thing. We don't actually do anything
' with the ID except check it is nonzero

lJobID = oFaxDoc.Send()
Set oFaxDoc = Nothing
End If
End If
' move to the next record
lSourceRecord = lSourceRecord + 1
Loop
End With

' All done. Restore the previous printer
' if necessary. You may need to tweak this
If Left(sActivePrinter, 3) <> sFaxPrinter Then
oApp.ActivePrinter = sActivePrinter
End If

Set oDataFields = Nothing
Set oMerge = Nothing
Set oDoc = Nothing

'Set oApp = Nothing

End If

If bFaxServerAvailable Then
oFaxServer.Disconnect
Set oFaxServer = Nothing
End If

End Sub

'-----------------------------------------------------

--
Peter Jamieson - Word MVP

Peter Jamieson said:
OK, I realised I didn't test the "image" part of your merge and when I did
that I had a similar result to the one you reported - whatever I do the
image is shifted to a new page and fills that page. The simple text
formatting I used in testing does, however, survive.

I'm currently asking around on this one, and have one or two more ideas, but
they will take some time to work through and may come to nothing.

--
Peter Jamieson - Word MVP

Raphaël Vanney said:
Hi Peter.

First off, let me thank you for a most comprehensive and knowledgeable
answer. I appreciate it.
I applied your suggestion ; the only missing thing in my case was the file
you mention in (d). What this changed is that I now have the "Merge to fax"
button enabled in the mail merge toolbar: so I guess we can call it a
success so far !

However, when I perform a mail merge to the fax, what happens is... Word
transfers the faxes to Outlook, which sends them to MS Fax... As opposed to
what happens when doing a File/Send to/Fax in Word, where Word sends the
document directly to MS Fax.
Needless to say, in the mail merge situation, the formatting is lost
somewhere between Outlook and MS Fax (when I check the documents in
Outlook's Outbox, it's still looking okay).

Bummer...?

I tried to see if I could spot anything in Outlook's configuration that
could explain this, but apparently there's nothing...

Argh !

R.
fax
making
it
work and am not sure what I did will work for you.

Assuming you want to use a FaxModem attached directly to your PC, the
necessary conditions seem to be that
a. you have installed the Windows XP Fax service software. I think
that
now
happens by default, but if not you can do it from Control Panel|Add or
Remove Programs|Add/Remove Windows Components.
b. you have added the Fax service to your Outlook Profile. These days you
probably need to do that in Outlook|Tools|Options|Mail Setup|E-mail
Accounts|E-mail - View or change existing e-mail accounts|Add|Additional
Server types|Fax Mail Transport. Then select it in the list of "e-mail"
accounts and click Change to set up the properties.
c. your fax numbers (in your Excel spreadsheet) are in the format

[FAX:0123456789]

(i.e. open square bracket, "FAX:", the number, close square bracket

d. You have a file called msmail.ini in your Windows directory (or WINNT
directory or whatever) with at least the following lines:

[EFAX Transport]
LocalFax=1

e. the file win.ini in the Windows directory has at least the following
lines:

[Mail]
MAPI=1
MAPIX=1

You may also need

CMC=1
CMCDLLNAME=mapi.dll
CMCDLLNAME32=mapi32.dll
MAPIXVER=1.0.0.1
OLEMessaging=1

but I don't think they are essential.

(a) and (b) essentially enable the fax service and make it available, (d)
and (e) enable the relevant buttons/optoins in Word mailmerge, and (c) makes
the MAPI spooler which Word sends its output to recognise which
transport
to
send the messages to.

If you do attempt this and manage to make it work, please post back
here.
 
R

Raphaël Vanney

Peter,

Thanks again for your answer. As it turns out, I had pretty much given up
the idea of customizing my faxes, but it's good to be on track again !
I will try your macro shortly and will let you know how it turns out. Not
that I am too familiar with VB, but I used to be a developper in another
life so there's a chance I can read it.
More on this later...

R.

Peter Jamieson said:
but
they will take some time to work through

It took a while, but if you are still interested...

First, it turns out that the merge-to-fax approach we tried (which has to go
via Outlook) has never worked properly in Win2k and later where the document
contained images. As far as I can tell this must result from a problem in
the way that Outlook renders message content when it "prints" fax messages
to the fax printer/service.

Second, I do not know if you tried using the mail to Internet Fax service
feature in Word 2003 (e.g. signing up with Venali), or whether you really
prefer to send your faxes directly using your faxmodem. The trouble is that
as things stand, neither approach works as it stands with a merge. If you
want to use the former, I have a sequence of instructions from Russ
Valentine that may work. If you prefer to use your own faxmodem, I've
developed the following Word VBA macro, which seems to work OK here and has
the advantage of bypassing Outlook altogether.

If you're going to try it, please read the notes, modify the macro to suit
your needs, and test it (I have done a certain amount of testing here and it
seems to work with single- and multi-page documents with text and images,
with and without cover pages, but I have not done an awful lot of testing.
FWIW I've tested with Word 2000 SP2 on WIn2K and Word 2003 on WinXP but not
Word 2002). I would be interested in any feedback you may have, either in
here or despam my address and e-mail me.

If you're unfamiliar with VBA etc. getting this to work could be quite
difficult. A useful starting point is the Word MVPs site at
http://www.mvps.org/word , and specifically the following "get-you-started"
article

http://www.mvps.org/word/FAQs/MacrosVBA/CreateAMacro.htm

Also, please note that I am likely to be "off-air" for the next few days so
may not be able to respond quickly to any questions.

The macro code:

'-----------------------------------------------------
Sub MergeOneFaxPerSourceRec()

' Disclaimer: Use this macro at your own risk.
' Purpose: Perform one Word mailmerge for each record in
' a Word data source, sending the results of each
' merge to a different fax number specified in a
' column of the data source
' Author: Peter J Jamieson
' Date: November 2003
' Assumes: Word 2000 or later (Word 97 might work)
' Windows 2000 or later, with the standard
' fax service software installed and
' configured to use a working fax device
' You have used Tools|References in the VBA
' editor to add the appropriate type library
' ("Faxcom 1.0 Type Library")
' You correctly adapt the macro to your
' environment
' Overview: The routine performs one merge per record
' in the data source. For each merge, the macro:
' - creates a new Word document
' - "prints" the document to the Fax printer,
' but outputting the result to a .tif file
' rather than allowing the fax printer to
' send the fax directly. This allows us to
' specify the fax number etc. in the macro
' rather than having to respond to the fax
' printer's dialog box.
' - submits the tif file to the fax service
' - discards the Word document
'
' Notes: This does not use the Extended Fax client API
' because it is not available in Windows 2000.
'
' This macro relies on the fax service to deliver
' the faxes once trhey have been submitted. You
' should use the fax service to verify which faxes
' have been sent and which, if any, failed. The fax
' service should retain a copy of each fax submitted
' so that retransmission should be feasible from
' within the service, i.e. without re-running the
' merge.

' NB, needs bettor error management and doubtless other
' things a VBA expert would point out.

' Specify the path for the .tif files saved by the Fax Printer
' This path must exist and the name should end with "\"
Const sTifFolder = "c:\tif\"
' Specify the name of the .tif file to output
Const sTifFile = "mergetif.tif"
' Specify the fax printer name that makes it all work
Const sFaxPrinter = "Fax"

Dim bFaxPortAvailable As Boolean
Dim bFaxServerAvailable As Boolean

Dim bTerminateMerge As Boolean

Dim lJobID As Long
Dim lSourceRecord As Long

Dim oApp As Word.Application
Dim oDataFields As Word.MailMergeDataFields
Dim oDoc As Word.Document
Dim oFaxDoc As FAXCOMLib.FaxDoc
Dim oFaxPort As FAXCOMLib.FaxPort
Dim oFaxPorts As FAXCOMLib.FaxPorts
Dim oFaxServer As FAXCOMLib.FaxServer
Dim oMerge As Word.MailMerge

Dim sActivePrinter As String
Dim sTifPath As String

' Phase 1.
' Connect to the Fax server
' and optionally see if a Port is available

Set oFaxServer = CreateObject("FaxServer.FaxServer")

If oFaxServer Is Nothing Then
MsgBox "Could not create a fax server object"
bFaxServerAvailable = False
Else
' This should connect us to the fax server on the current machine
oFaxServer.Connect Servername:=Environ("computername")
bFaxServerAvailable = True
bFaxPortAvailable = True

' begin optional section
' - ensure that at least one output port is available
' - not essential but we will just see an error later
' if no output port is available
Set oFaxPorts = oFaxServer.GetPorts
If oFaxPorts.Count = 0 Then
MsgBox "The fax server has no fax devices"
bFaxPortAvailable = False
Else
' look for a port that can send
For i = 1 To oFaxPorts.Count
Set oFaxPort = oFaxPorts.Item(i)
If oFaxPort.Send = 0 Then
Set oFaxPort = Nothing
Else
Exit For
End If
Next
If oFaxPort Is Nothing Then
MsgBox "The fax server has no ports configured to send faxes"
bFaxPortAvailable = False
Else
' at the moment we do not use the FaxPort object to get status
' info. so just get rid of it
Set oFaxPort = Nothing
End If
End If
' we do not need this either
Set oFaxPorts = Nothing
' end optional section

End If

' Phase 2.
' We can fax, so set up the printer
' and start the merges.

If bFaxServerAvailable And bFaxPortAvailable Then

' You may need to change this
Set oApp = Application

' The mail merge main document is assumed
' to be the active document in the current
' instance of Word
Set oDoc = oApp.ActiveDocument
Set oMerge = oDoc.MailMerge
Set oDataFields = oMerge.DataSource.DataFields

' save and set up the active printer
sActivePrinter = oApp.ActivePrinter
' don't change the printer if it is already
' correctly set up
' (I had problems when I tried to switch
' to the fax printer in code)
' you may need to adjust this for your
' fax printer name
If Left(sActivePrinter, 3) <> sFaxPrinter Then
oApp.ActivePrinter = sFaxPrinter
End If

With oMerge

' If no data source has been defined,
' do it here using OpenDataSource.
' But if it is already defined in the document,
' you should not need to define it here.

' .OpenDataSource _
' Name:="whatever"

lSourceRecord = 1
bTerminateMerge = False

Do Until bTerminateMerge
.DataSource.ActiveRecord = lSourceRecord

' if we have gone past the end
' (and possibly, if there are no records)
' then the Activerecord will not be what
' we have just tried to set it to

If .DataSource.ActiveRecord <> lSourceRecord Then
bTerminateMerge = True
Else
.DataSource.FirstRecord = lSourceRecord
.DataSource.LastRecord = lSourceRecord
.Destination = wdSendToNewDocument
.Execute

' Word always sets the output document produced
' by the merge to be the ActiveDocument

' Now print to the fax printer, specifying an
' OutputFileName.
' Specifying Background:=False is
' particularly important or the fax stage
' will fail later

' create the full path name for the file.
' (done separately so you can change the way
' you create the name and re-use the name later)

sTifPath = sTifFolder + sTifFile
oApp.PrintOut _
Background:=False, _
Append:=False, _
Range:=wdPrntAllDocument, _
OutputFileName:=sTifPath, _
Item:=wdPrintDocumentContent, _
Copies:=1, _
PageType:=wdPrintAllPages, _
PrintToFile:=True

' Don't need the document any more
oApp.ActiveDocument.Close Savechanges:=False

' Now make a FaxDocument
Set oFaxDoc = oFaxServer.CreateDocument(sTifPath)
If oFaxDoc Is Nothing Then
MsgBox "Could not create the fax document"
' you could consider finishing here by setting
' TerminateMerge = True
Else
' fill in whatever details you need
' from the data source or elsewhere
With oFaxDoc
' The number to send to. The only really essential
' piece of information. Here we get it from
' a field in the data source called "faxnumber"
.FaxNumber = oDataFields("faxnumber")

' DisplayName is a "user-friendly" name used
' by the Fax Server when you e.g. inspect the
' current fax status

' here we get it from a field in the data source
' called ufname
.DisplayName = oDataFields("ufname")
' here we just set it to ""
'.DisplayName = ""

' If you want a cover page, set SendCoverPage
' to a nonzero value. You could define whether
' or not you want a cover page, and which
' page to use, in your data source. However,
' if you specify a cover page, you /must/
' provide a valid name for the page. This code
' does not verify whether you do or not.
.SendCoverpage = 0

' If the cover page (.cov file) is a common
' cover page located on the server (i.e. in the
' default folder), set ServerCoverPage=-1
' and provide the name of the cover page
' If the cover page is somewhere else,
' set ServerCoverPage=0 and specify the
' full path name of the cover page
.ServerCoverpage = 1
.CoverpageName = ""

' The following items may be used in the coverpage
' or they may be displayed in fax service status
' dialog boxes. The items visible in the Win2000
' fax status are indicated by
'** displayed in dialog

.CoverpageNote = ""
.CoverpageSubject = ""
.EmailAddress = ""
.RecipientAddress = ""
.RecipientCity = ""
.RecipientCompany = ""
.RecipientCountry = ""
.RecipientDepartment = ""
.RecipientHomePhone = ""
'** displayed in dialog
.RecipientName = ""
.RecipientOffice = ""
.RecipientOfficePhone = ""
.RecipientState = ""
.RecipientTitle = ""
.RecipientZip = ""
.SenderAddress = ""
'** displayed in dialog
.SenderCompany = ""
'** displayed in dialog
.SenderDepartment = ""
.SenderFax = ""
.SenderHomePhone = ""
'** displayed in dialog
.SenderName = ""
.SenderOffice = ""
.SenderOfficePhone = ""
.SenderTitle = ""

'** displayed in dialog
.BillingCode = ""

' DiscountSend = 0 means "send immediately
' If you have set up discount periods, setting
' DiscountSend to a nonzero value will make the
' fax service send in a discount period
.DiscountSend = 0

' In theory, the TSID is the Fax sender ID printed
' on the fax, i.e. typically your contact fax number,
' but the value set up in the fax service appears to
' override any value set here.
'.Tsid = ""
End With

' Now send the thing. We don't actually do anything
' with the ID except check it is nonzero

lJobID = oFaxDoc.Send()
Set oFaxDoc = Nothing
End If
End If
' move to the next record
lSourceRecord = lSourceRecord + 1
Loop
End With

' All done. Restore the previous printer
' if necessary. You may need to tweak this
If Left(sActivePrinter, 3) <> sFaxPrinter Then
oApp.ActivePrinter = sActivePrinter
End If

Set oDataFields = Nothing
Set oMerge = Nothing
Set oDoc = Nothing

'Set oApp = Nothing

End If

If bFaxServerAvailable Then
oFaxServer.Disconnect
Set oFaxServer = Nothing
End If

End Sub

'-----------------------------------------------------

--
Peter Jamieson - Word MVP

Peter Jamieson said:
OK, I realised I didn't test the "image" part of your merge and when I did
that I had a similar result to the one you reported - whatever I do the
image is shifted to a new page and fills that page. The simple text
formatting I used in testing does, however, survive.

I'm currently asking around on this one, and have one or two more ideas, but
they will take some time to work through and may come to nothing.

--
Peter Jamieson - Word MVP

Raphaël Vanney said:
Hi Peter.

First off, let me thank you for a most comprehensive and knowledgeable
answer. I appreciate it.
I applied your suggestion ; the only missing thing in my case was the file
you mention in (d). What this changed is that I now have the "Merge to fax"
button enabled in the mail merge toolbar: so I guess we can call it a
success so far !

However, when I perform a mail merge to the fax, what happens is... Word
transfers the faxes to Outlook, which sends them to MS Fax... As
opposed
to
what happens when doing a File/Send to/Fax in Word, where Word sends the
document directly to MS Fax.
Needless to say, in the mail merge situation, the formatting is lost
somewhere between Outlook and MS Fax (when I check the documents in
Outlook's Outbox, it's still looking okay).

Bummer...?

I tried to see if I could spot anything in Outlook's configuration that
could explain this, but apparently there's nothing...

Argh !

R.


I have this interesting (to me) problem that's driving me completely
nuts.

Believe me, you are not alone.

I use the mail merge to e-mail feature, since merging directly to
fax
is
no
longer available.

As far as I can tell, it is, probably. However, I had difficulty
making
it
work and am not sure what I did will work for you.

Assuming you want to use a FaxModem attached directly to your PC, the
necessary conditions seem to be that
a. you have installed the Windows XP Fax service software. I think that
now
happens by default, but if not you can do it from Control Panel|Add or
Remove Programs|Add/Remove Windows Components.
b. you have added the Fax service to your Outlook Profile. These
days
you
probably need to do that in Outlook|Tools|Options|Mail Setup|E-mail
Accounts|E-mail - View or change existing e-mail accounts|Add|Additional
Server types|Fax Mail Transport. Then select it in the list of "e-mail"
accounts and click Change to set up the properties.
c. your fax numbers (in your Excel spreadsheet) are in the format

[FAX:0123456789]

(i.e. open square bracket, "FAX:", the number, close square bracket

d. You have a file called msmail.ini in your Windows directory (or WINNT
directory or whatever) with at least the following lines:

[EFAX Transport]
LocalFax=1

e. the file win.ini in the Windows directory has at least the following
lines:

[Mail]
MAPI=1
MAPIX=1

You may also need

CMC=1
CMCDLLNAME=mapi.dll
CMCDLLNAME32=mapi32.dll
MAPIXVER=1.0.0.1
OLEMessaging=1

but I don't think they are essential.

(a) and (b) essentially enable the fax service and make it
available,
(d)
and (e) enable the relevant buttons/optoins in Word mailmerge, and (c)
makes
the MAPI spooler which Word sends its output to recognise which transport
to
send the messages to.

If you do attempt this and manage to make it work, please post back here.
 
R

Roger Beall

Tried it .. worked great after adding one line in word
2003 That line is at the very end:


oApp.Quit SaveChanges:=False



Set oDataFields=Nothing
<and the rest>

<10 lines from the bottom of the routine.>
Gotta quit before setting to nothing to free the memory.
 
R

Raphaël Vanney

Hmmm... that certainly is the most valuable piece of help I ever got from
usenet ! (and I've been there for a while!)
Peter, your macro works beautifully and does exactly what I had been trying
to achieve ! Thanks a bunch !

The only warning you could add at the beggining of your code is that the
macro will halt if the document contains a conditional skip instruction and
that condition is met. The easy workaround is, of course, to clean-up the
data source so that it contains only valid records.

A big thanks once again,

R.
 
P

Peter Jamieson

Raphaël,

Glad the macro did what you needed, and thanks for the useful feedback.
The only warning you could add at the beggining of your code is that the
macro will halt if the document contains a conditional skip instruction and
that condition is met. The easy workaround is, of course, to clean-up the
data source so that it contains only valid records.

OK, good point.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top