J
JGOV
Hi, I think I am in the right place for this question so here goes. I am
automating mail merge using word 2003 object model. My question is, is there
a way to suppress the fillin field prompt? I do not have access to change
the templates and do not have access to the datasource and this process must
be completely without user input. Here is my current code.
//Open Template Document
Dim WordDoc As Word.Document = p_WordApp.Documents.Open(sPath + "\" + sFile)
//Open DataSource Document
WordDoc.MailMerge.OpenDataSource(Name:=sPath + "\Datasource" + sFile +
".csv", ReadOnly:=False, LinkToSource:=False, Connection:="",
SQLStatement:="", SQLStatement1:="")
//Verify DataSource has correct fields per its corresponding template
If VerifyMergeFields(WordDoc) Then
With .MailMerge
..Destination = Word.WdMailMergeDestination.wdSendToNewDocument
..SuppressBlankLines = True
With .DataSource
..FirstRecord = Word.WdMailMergeDefaultRecord.wdDefaultFirstRecord
..LastRecord = Word.WdMailMergeDefaultRecord.wdDefaultLastRecord
End With
..Execute(Pause:=False) <-- Prompts Occur Here
End With
//Save and Close merged Document
p_WordApp.ActiveDocument.SaveAs(sPath + "\MergedDoc" + sFile)
p_WordApp.ActiveDocument.Close()
//Close template Document
WordDoc.Close(False, False)
WordDoc = Nothing
//Check for Error Documents since pause was set to False and save/close
them.
For Each oDocument As Word.Document In p_WordApp.Documents
If Not
Directory.Exists(Path.GetDirectoryName(Reflection.Assembly.GetExecutingAssembly.Location) & "\ErrorLog") Then
Directory.CreateDirectory(Path.GetDirectoryName(Reflection.Assembly.GetExecutingAssembly.Location) & "\ErrorLog")
End If
oDocument.SaveAs(Path.GetDirectoryName(Reflection.Assembly.GetExecutingAssembly.Location) & "\ErrorLog\" & sFile & "_" & oDocument.Name & ".Doc")
oDocument.Close()
Next
//Remove unneeded datasource and template
File.Delete(sPath + "\Datasource" + sFile + ".csv")
File.Delete(sPath + "\" + sFile)
End If
automating mail merge using word 2003 object model. My question is, is there
a way to suppress the fillin field prompt? I do not have access to change
the templates and do not have access to the datasource and this process must
be completely without user input. Here is my current code.
//Open Template Document
Dim WordDoc As Word.Document = p_WordApp.Documents.Open(sPath + "\" + sFile)
//Open DataSource Document
WordDoc.MailMerge.OpenDataSource(Name:=sPath + "\Datasource" + sFile +
".csv", ReadOnly:=False, LinkToSource:=False, Connection:="",
SQLStatement:="", SQLStatement1:="")
//Verify DataSource has correct fields per its corresponding template
If VerifyMergeFields(WordDoc) Then
With .MailMerge
..Destination = Word.WdMailMergeDestination.wdSendToNewDocument
..SuppressBlankLines = True
With .DataSource
..FirstRecord = Word.WdMailMergeDefaultRecord.wdDefaultFirstRecord
..LastRecord = Word.WdMailMergeDefaultRecord.wdDefaultLastRecord
End With
..Execute(Pause:=False) <-- Prompts Occur Here
End With
//Save and Close merged Document
p_WordApp.ActiveDocument.SaveAs(sPath + "\MergedDoc" + sFile)
p_WordApp.ActiveDocument.Close()
//Close template Document
WordDoc.Close(False, False)
WordDoc = Nothing
//Check for Error Documents since pause was set to False and save/close
them.
For Each oDocument As Word.Document In p_WordApp.Documents
If Not
Directory.Exists(Path.GetDirectoryName(Reflection.Assembly.GetExecutingAssembly.Location) & "\ErrorLog") Then
Directory.CreateDirectory(Path.GetDirectoryName(Reflection.Assembly.GetExecutingAssembly.Location) & "\ErrorLog")
End If
oDocument.SaveAs(Path.GetDirectoryName(Reflection.Assembly.GetExecutingAssembly.Location) & "\ErrorLog\" & sFile & "_" & oDocument.Name & ".Doc")
oDocument.Close()
Next
//Remove unneeded datasource and template
File.Delete(sPath + "\Datasource" + sFile + ".csv")
File.Delete(sPath + "\" + sFile)
End If