Microsoft Office Tutorials and References
In Depth Information
Mail Merge: Creating a One-to-Many List
'Insert the data string¶
rng.Text = list¶
'Convert it to a table¶
Set tbl = rng.ConvertToTable(Separator:=sepChar,
NumColumns:=nrCols)¶
'Restore the bookmark around the table¶
rng.Parent.Bookmarks.Add Range:=tbl.Range, Name:=BookmarkName¶
FormatTable tbl¶
End Sub¶
' * * * * *¶
Sub FormatTable(tbl As Word.Table)¶
'Variable declaration¶
Dim cel As Word.Cell¶
Dim s As String¶
'Bold the header row¶
With tbl.Rows(1).Range.Font¶
.Bold = True¶
.Underline = wdUnderlineSingle¶
End With¶
'Center the last column¶
tbl.Columns(tbl.Columns.Count).Select¶
For Each cel In Selection.Cells¶
cel.Range.Paragraphs.Alignment = wdAlignParagraphCenter¶
Next cel¶
tbl.Columns.AutoFit¶
tbl.Borders.Enable = False¶
End Sub¶
' * * * * *¶
Sub ActivateEvents()¶
Set MergeEvents.WdApp = Word.Application¶
End Sub¶
' * * * * *¶
Sub DeactivateEvents()¶
Set MergeEvents = Nothing¶
End Sub¶
Wrd
View the Appendix to learn how to store this procedure
in a Class module.
Option explicit
' * * * * *¶
Public WithEvents WdApp As Word.Application¶
Const sMergeMessage As String = "The merge process can take some time."
& _¶
vbCr & vbCr & "Word may pause and seem to hang while the charts
update." _¶
& vbCr & vbCr & "Please do NOT try to work " & _¶
"in Word until the 'finish' message has been displayed!"¶
Private rs As ADODB.Recordset¶
Search JabSto ::




Custom Search