0
我有一個用於Word的VB.NET VSTO AddIn。Word MailMerge部分範圍
在這個項目中,我需要執行MailMerge操作,但只適用於MergeSource的部分範圍。
在這個例子中,我們假設MergeSource包含100個收件人。 我只想包含收件人11-20。
通常我會做以下操作,但是這包括所有收件人。
Sub ExecuteMerge(ByRef Doc As Word.Document)
Doc.MailMerge.Execute(False)
End Sub
我想做什麼就能做的,是這樣的:
Sub ExecuteMerge(ByRef Doc As Word.Document, Optional StartPos As Integer = 0, Optional EndPos As Integer = 0)
If StartPos > 0 AndAlso StartPos <= Doc.MailMerge.DataSource.RecordCount Then
Doc.MailMerge.StartPosition = StartPos
Else
Doc.MailMerge.StartPosition = 1
End If
If EndPos > StartPos AndAlso EndPos <= Doc.MailMerge.DataSource.RecordCount Then
Doc.MailMerge.EndPosition = EndPos
Else
Doc.MailMerge.EndPosition = Doc.MailMerge.DataSource.RecordCount
End If
Doc.MailMerge.Execute(False)
End Sub
注:.StartPosition
和.EndPosition
僅僅是僞代碼,它不存在,作爲一個屬性。
這就是我要找的。如何將收件人的範圍設置爲包含在合併中?
Word必須能夠做到這一點,因爲當我手動執行郵件合併,我得到這個對話框: