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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

conditional font in mail merge labels

Status
Not open for further replies.

lespaul

Programmer
Feb 4, 2002
7,083
US
I have an automated mail merge (through a Delphi program). I have a mail merge label template that I open (it's datasource is an excel spreadsheet) and print (all done in the background, no user interface).

So now I have several pages of labels that have the following information:

5792 - Joe Blow 5793 - Jane Ms Smith 5794 - Mary Jones

etc.

What I would like to do on the resulting Labels1 document of the mail merge is search each cell and see if any of the following exist in the cell: MR, MS, MRS, MISS, JR, SR (that's as far as I'm willing to go!). If one of the above exist, set THAT CELL'S font to Bold to make it easier for users to spot the ones that need correcting.

Any suggestions? Thanks!


Leslie

There are 10 types of people in the world -
those who understand binary
and
those who don't!
 
Hi,

I hope the following code could help you ...
I've just written the part for seraching "mr" but I think it will be easy to do a loop for the others

SEB

***********************************************************
Sub Lespaul()
Dim myCell As Range

On Error GoTo error_handler

Range("A1").Activate

Cells.Find("mr", ActiveCell, xlFormulas, xlPart, xlByRows, xlNext, False).Activate
'*** if text not found => error handler ***
Set myCell = ActiveCell
ActiveCell.Font.Bold = True
Cells.FindNext(ActiveCell).Activate

While Not ActiveCell.Address = myCell.Address
ActiveCell.Font.Bold = True
Cells.FindNext(ActiveCell).Activate
Wend

Exit Sub

error_handler:
If Err.Number = 91 Then
MsgBox "text not found"
Else
MsgBox Err.Description, vbOKOnly, Err.Number
End If

End Sub

***********************************************************
 
Thanks! So, I put this in the module of my mail merge template. I know the new document that is created is named Labels1, how do I make the new Labels1 document the active document?

(I tried searching, but it's down for maintenance!)

Les

 
Put this in an Excel Module and then run the macro

SEB
 
So if I put the macro in my template and run it, it will know to search the new labels document?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top