Mailing por fax desde el mismo cliente
Nota: Ésta es la vista de impresión del Manual de referencia completo en una sola página. Si lo prefiere puede encontrar la versión original aquí.
1. Requisitos para poder hacerlo
- Cliente WHFC instalado en el equipo. La impresora que hemos instalado debe llamarse “hylafax”, sino no funcionará esto
- Microsoft Word / Excel (pruebas hechas con 97 y 2000 y va OK)
- El campo de combinación que contiene el nº de fax, debe llamarse “fax”
2. Combinación de Word

Además tenemos que tener el Documento Excel desde donde sacaremos los datos de las empresas a las que queremos enviar el fax.

En Word tenemos que indicarle que nos coja los datos de este fichero. Para ello, tenemos lo siguiente : Herramientas: Combinar Correspondencia
Y le elegimos el fichero Excel donde están los datos de las empresas.
3. Macro a añadir en Word
Podemos hacerlo de diferentes formas. Modificar la plantilla normal.dot del equipo, con lo que todos los documentos creados con dicho ordenador incluirían la macro, o crear una plantilla especial y luego crear los documentos de tipo mailing apartir de dicha plantilla especial. Esto a gusto de consumidor.
La macro a añadir en cuestión es la siguiente
Sub MergeFax()
'
' MergeFax Macro
' Macro created 08/11/98 by Keith Gray
' Modified for full-blown Mailmerge 10/30/00 by Michael DeWitt
'
' This version will create a mailmerge with output for each record to be merged and produce a PS file suitable for Hylafax. The script
' was tested with word97 sr-1. Consider the first page of your merge document to be the cover page. The number of pages might be able to
'be determined in VBA, but I just type it into the body of the document (since all of the faxes are the same length.
' How to use this script:
'1. Create your mailmerge document
'2. Run the mailmerge script setting your main document and data source.
'3. Modify the line setting datafields("fax") to be the correct name of the fax number field in your merge document.
'4. Make sure that the merge document is the "active" document (if you have other documents open in Word).
'5. call your hylafax printer (created for WHFC) "hylafax" or modify the name in the script below. (it needn't be this printer, but why create another PS Printer?
'It is important to note that the WHFC does not support killtime as of yet and so if you are sending a lot of faxes, you may find that some of them are are killed before
'they even get a chance to be sent. In a dual modem hylafax server, sending a 6 page fax, 5-6 faxes were aborted before they had a chance to be
'sent.
Dim whfc As Object
Dim OLE_Return As Long
Dim faxnum As String
Dim SpoolFile As String
Dim Template As String
Dim Tempfile As String
Dim mergedfile As String
Dim Title As String
Dim WhfcPrinter As String
Dim Default_Active_Printer As String
Dim Box_Return As Integer
' MsgBox ActiveDocument.Name
ActiveDocument.MailMerge.ViewMailMergeFieldCodes = True
ActiveDocument.MailMerge.DataSource.ActiveRecord = wdLastRecord
Numb_Faxes = ActiveDocument.MailMerge.DataSource.ActiveRecord
ActiveDocument.MailMerge.DataSource.ActiveRecord = wdFirstRecord
Template = ActiveDocument.Name
For I = 1 To Numb_Faxes
SpoolFile = Environ("Temp") & "\fax" & I & ".ps"
Title = "WHFC Mail Merge to Fax Macro( Version 1.1 )"
faxnum = ActiveDocument.MailMerge.DataSource.DataFields("fax") '<===Change
"fax" to be the correct name of the fax number field
With ActiveDocument.MailMerge
.DataSource.FirstRecord = I
.DataSource.LastRecord = I
.Destination = wdSendTofile
.SuppressBlankLines = True
.Execute
End With
' MsgBox ActiveDocument.Name
Tempfile = ActiveDocument.Name
WhfcPrinter = "Hylafax"
Default_Active_Printer = ActivePrinter
'MsgBox ActivePrinter
ActivePrinter = WhfcPrinter$
'Note: background must be false in order to work - this is do to some kind
of bug in VBA
Application.PrintOut FileName:="", Range:=wdPrintAllDocument, _
Item:=wdPrintDocumentContent, Copies:=1, Pages:="", _
PageType:=wdPrintAllPages, Collate:=True, Background:=False, _
PrintToFile:=True, OutputFileName:=SpoolFile, Append:=False
Set whfc = CreateObject("WHFC.OleSrv")
OLE_Return = whfc.SendFax(SpoolFile, faxnum, True)
' MsgBox OLE_Return 'if you activate this you will see the fax job number
from hylafax.
If OLE_Return <= 0 Then
Box_Return = MsgBox("Error sending file", 16, Title)
Else
'Box_Return = MsgBox(OLE_Return, 0, Title)
End If
Set whfc = Nothing
Documents(Tempfile).Close (False)
Documents(Template).Activate
ActiveDocument.MailMerge.DataSource.ActiveRecord = wdNextRecord
Next I
ActivePrinter = Default_Active_Printer$
End Sub
Tenemos que tener alguna cosa en cuenta. La impresora que hemos añadido al instalar el cliente de hylafax, tiene que llamarse “hylafax” para que esta macro funcione.
Y otra cosilla más: el campo en Excel que contiene el nº de fax, debe llamarse “fax”, sino habría que cambiar la macro.
4. ¿Cómo meter la macro en el documento?
Para ello Herramientas: Macro: Macros.

Le damos a Crear:
Y nos llevará al editor de Visual Basic. Pegamos ahí el código de la macro y listo

5. ¿Cómo ejecutar la macro?
Una vez tenemos todo esto hecho, tan solo queda ejecutar la macro, para ello Herramientas: Macro: Macros:

Y empezará el proceso de lanzar faxes.
