Thread: mailmerge event
View Single Post
  #1   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Caroline Caroline is offline
external usenet poster
 
Posts: 30
Default mailmerge event

Hi

I have a template with a table and a merge this template with my data. If
there is a value for a field in a cell the border is visible and the shading
is grey. If there is no value the border and shading are not visible.
I have some trouble to run my macro on the mailmerge event. I would like to
run the macro when i use the "mail merge" button in my tool bar.

I am not technical.... could you tell me what is wrong in my macro?

Thank you

Sub caro()
'
' test Macro
' Macro créée le 24/11/2007 par caro

With ActiveDocument.MailMerge

Dim intCount As Integer
Dim limCount As Integer

With ActiveDocument.MailMerge.DataSource

.ActiveRecord = wdLastRecord
intCount = .ActiveRecord

'Set the active record equal to the first record in the data source
.ActiveRecord = wdFirstRecord
limCount = .ActiveRecord

Do While limCount = intCount

'Set the condition that will change the border and shading of a
specific cell
If .DataFields("CodeRel").Value = 1 Then

Set mycell = ActiveDocument.Tables(1).Cell(Row:=4,
Column:=6)
mycell.Range.Text = OrigSeqNum
mycell.Shading.BackgroundPatternColor = wdColorGray20
mycell.Borders.Enable = True

End If

Set mycell = ActiveDocument.Tables(1).Cell(Row:=4,
Column:=6)
mycell.Range.Text = ""
mycell.Shading.BackgroundPatternColor = wdColorWhite
mycell.Borders.Enable = False

'Move the record to the next record in the data source

.ActiveRecord = wdNextRecord
limCount = limCount + 1

Loop

End With

End With

End Sub