We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

RemoveUnusedRegions

I’m having trouble getting rid of an unused region in one of my documents. I’ve tried every combination of the cleanup flags and nothing works. I’ve been able to get rid of unused merge fields in other documents, but not unused regions. What am I missing?

Dim doc as new Document(TemplatePath & “AuditRecordsReceived.dotx”)
'Merge non-repeating data
doc.MailMerge.UseNonMergeFields = True
doc.MailMerge.Execute(assignmentData.Keys.ToArray(), assignmentData.Values.ToArray())
'Merge repeating data

doc.MailMerge.ExecuteWithRegions(reportDataSource)

'Cleanup
doc.MailMerge.CleanupOptions = (MailMergeCleanupOptions.RemoveEmptyParagraphs Or 
MailMergeCleanupOptions.RemoveUnusedRegions Or
<span style="color:#2b91af;">MailMergeCleanupOptions</span>.RemoveUnusedFields <span style="color:blue;">Or</span>
<span style="color:#2b91af;">MailMergeCleanupOptions</span>.RemoveContainingFields <span style="color:blue;">Or</span>
<span style="color:#2b91af;">MailMergeCleanupOptions</span>.RemoveStaticFields)

doc.UpdatePageLayout()

Hi Charles,


Thanks for your inquiry. Please use MailMerge.CleanupOption before calling MailMerge.ExecuteWithRegions. Moreover, there is no need to call UpdatePageLayout.

Dim doc as new Document(TemplatePath & “AuditRecordsReceived.dotx”)
'Merge non-repeating data
doc.MailMerge.UseNonMergeFields = True
doc.MailMerge.Execute(assignmentData.Keys.ToArray(), assignmentData.Values.ToArray())
'Cleanup
doc.MailMerge.CleanupOptions = (MailMergeCleanupOptions.RemoveEmptyParagraphs Or
MailMergeCleanupOptions.RemoveUnusedRegions Or
MailMergeCleanupOptions.RemoveUnusedFields Or
MailMergeCleanupOptions.RemoveContainingFields Or
MailMergeCleanupOptions.RemoveStaticFields)
'Merge repeating data
doc.MailMerge.ExecuteWithRegions(reportDataSource)
1 Like