昨天创建了一个word宏,代码如下
ActiveDocument.MailMerge.OpenDataSource Name:= _
"C:\Documents and Settings\Smile\桌面\新建 Microsoft Office Excel 工作表.xlsx", _
ConfirmConversions:=False, ReadOnly:=False, LinkToSource:=True, _
AddToRecentFiles:=False, PasswordDocument:="", PasswordTemplate:="", _
WritePasswordDocument:="", WritePasswordTemplate:="", Revert:=False, _
Format:=wdOpenFormatAuto, Connection:= _
"Provider=Microsoft.ACE.OLEDB.12.0;User ID=Admin;Data Source=C:\Documents and Settings\Smile\桌面\新建 Microsoft Office Excel 工作表.xlsx;Mode=Read;Extended Properties=""HDR=YES;IMEX=1;"";Jet OLEDB:System database="""";Jet OLEDB:Registry Path="""";Jet OLEDB:Engine Type" _
, SQLStatement:="SELECT * FROM `Sheet1$`", SQLStatement1:="", SubType:= _
wdMergeSubTypeAccess
Selection.MoveRight Unit:=wdCharacter, Count:=3
ActiveDocument.Fields.Add Range:=Selection.Range, Type:=wdFieldMergeField _
, Text:="""排名"""
With ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.SuppressBlankLines = True
With .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
End With
.Execute Pause:=False
End With
Windows("新建 Microsoft Office Word 文档 (2).docx").Activate
End Sub
请问 如果我用一个IList泛型或者datatable做为数据源的话,ActiveDocument.MailMerge.OpenDataSource 这一段该怎么写,
With .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
End With
这一段又该怎么写,哪位高手来帮帮忙啊~