C
Chris Wold
I am trying to automate a catalog merge from vb.net using the following code,
which I will explain below:
Public Sub PublisherExecuteMerge(ByVal fPath As String)
'Execute catalog merge in publisher
Dim fInfo As System.IO.FileInfo
Dim pubApp As Publisher.Application = Nothing
Dim pubDoc As Publisher.Document = Nothing
Dim mergeDoc As Publisher.MailMerge = Nothing
Try
pubApp = New Publisher.Application
pubApp.Open(Filename:=fPath, _
ReadOnly:=False, AddToRecentFiles:=False, _
SaveChanges:=Publisher.PbSaveOptions.pbDoNotSaveChanges)
pubApp.ActiveWindow.Visible = True
'Add a new docuemnt
pubDoc = pubApp.Documents.Add
mergeDoc = pubDoc.MailMerge
mergeDoc.Execute( _
True, _
Publisher.PbMailMergeDestination.pbMergeToNewPublication, _
"C:\temp\foo.pub")
Catch ex As Exception
MsgBox(ex.Message)
Finally
pubDoc = Nothing
mergeDoc = Nothing
pubApp = Nothing
GC.Collect()
End Try
End Sub
The full path to the template doc is given in "fPath". The template already
contains a catalog merge area, merge fields, and is linked to an ASCII
(tab-delimited text file) datasource. If I use publisher, I can open the
template and using the wizard, get the correct result and save it to a new
document. However, I need to do the same thing in vb.net. So what happens
when I run this sub is that the template is opened in Publisher and a new doc
is created. However the second document is empty and I get this error:
"System.ArgumentException: Value does not fall within the expected range"
which occurs when the sub attempts to execute the mail merge.
Can anyone help me with this?
Thank you,
Chris
which I will explain below:
Public Sub PublisherExecuteMerge(ByVal fPath As String)
'Execute catalog merge in publisher
Dim fInfo As System.IO.FileInfo
Dim pubApp As Publisher.Application = Nothing
Dim pubDoc As Publisher.Document = Nothing
Dim mergeDoc As Publisher.MailMerge = Nothing
Try
pubApp = New Publisher.Application
pubApp.Open(Filename:=fPath, _
ReadOnly:=False, AddToRecentFiles:=False, _
SaveChanges:=Publisher.PbSaveOptions.pbDoNotSaveChanges)
pubApp.ActiveWindow.Visible = True
'Add a new docuemnt
pubDoc = pubApp.Documents.Add
mergeDoc = pubDoc.MailMerge
mergeDoc.Execute( _
True, _
Publisher.PbMailMergeDestination.pbMergeToNewPublication, _
"C:\temp\foo.pub")
Catch ex As Exception
MsgBox(ex.Message)
Finally
pubDoc = Nothing
mergeDoc = Nothing
pubApp = Nothing
GC.Collect()
End Try
End Sub
The full path to the template doc is given in "fPath". The template already
contains a catalog merge area, merge fields, and is linked to an ASCII
(tab-delimited text file) datasource. If I use publisher, I can open the
template and using the wizard, get the correct result and save it to a new
document. However, I need to do the same thing in vb.net. So what happens
when I run this sub is that the template is opened in Publisher and a new doc
is created. However the second document is empty and I get this error:
"System.ArgumentException: Value does not fall within the expected range"
which occurs when the sub attempts to execute the mail merge.
Can anyone help me with this?
Thank you,
Chris