M
Matt Barton
Hi,
I'm having a problem executing a word mailmerge automated by an ActiveX
control embedded in an intranet web page.
I have an intranet application which allows users to upload word
mailmerge main documents, and then have other users of the intranet
execute mailmerges with data in our intranet database.
It all works a treat except when one of my users uploads a mailmerge
main document which has been created using an edited normal.dot. In
these cases word opens an Open Header Source dialog box. I can then
select any word document I like, and the mailmerge completes successfully.
It is the Open Header Source dialog which I want to prevent - as it will
certainly confuse some of my less savvy users.
If that same mailmerge main document is used on the machine that created
it, it works fine, without the extra dialog.
My code, for this part of the system, for what it's worth is:
'------------------------------------------------------------
Set objMSWordInstance = New Word.Application
' using the new word application ...
With objMSWordInstance
' make word visible
.Visible = True
' activate word applciation
.Activate
' create new instance of word document
Set objDummyDocument = objMSWordInstance.Documents.add()
' close the dummy document
objDummyDocument.Close (wdDoNotSaveChanges)
' create new instance of word document using the saved mailmerge
template
Set objSourceDocument = .Documents.Open(strMailmergeTemplateFilename)
' create new instance of Word mailmerge object
Set objMailMerge = objSourceDocument.MailMerge
' using the new mailmerge object ...
With objMailMerge
.OpenHeaderSource strHeaderRecordFilename, wdOpenFormatText,
False, True
' use the temporary file we've just created as the word
mailmerge data source
.OpenDataSource strFieldValuesTempFilename, wdOpenFormatText,
False, True
' set the last record property of the data source
' (this means that the blank record we stuck on the end
' of the data records will not be displayed)
.DataSource.LastRecord = intTotalRealRecords + 1
' execute the mailmerge!
.Execute (True)
End With
' dereference mail merge object
Set objMailMerge = Nothing
' close the original source document (discarding changes)
objSourceDocument.Close (wdDoNotSaveChanges)
' dereference word document object
Set objSourceDocument = Nothing
End With
' ---------------------------------------------------------
Debugging has told me that it is the .OpenHeaderSource command which is
causing the dialog to open.
In the above code the strHeaderRecordFilename variable is the path &
filename of a text document which holds the merge field names. The data
records are held in a text file for which the strFieldValuesTempFilename
variable holds the path & filename.
Does anyone have any suggestions?
Matt
I'm having a problem executing a word mailmerge automated by an ActiveX
control embedded in an intranet web page.
I have an intranet application which allows users to upload word
mailmerge main documents, and then have other users of the intranet
execute mailmerges with data in our intranet database.
It all works a treat except when one of my users uploads a mailmerge
main document which has been created using an edited normal.dot. In
these cases word opens an Open Header Source dialog box. I can then
select any word document I like, and the mailmerge completes successfully.
It is the Open Header Source dialog which I want to prevent - as it will
certainly confuse some of my less savvy users.
If that same mailmerge main document is used on the machine that created
it, it works fine, without the extra dialog.
My code, for this part of the system, for what it's worth is:
'------------------------------------------------------------
Set objMSWordInstance = New Word.Application
' using the new word application ...
With objMSWordInstance
' make word visible
.Visible = True
' activate word applciation
.Activate
' create new instance of word document
Set objDummyDocument = objMSWordInstance.Documents.add()
' close the dummy document
objDummyDocument.Close (wdDoNotSaveChanges)
' create new instance of word document using the saved mailmerge
template
Set objSourceDocument = .Documents.Open(strMailmergeTemplateFilename)
' create new instance of Word mailmerge object
Set objMailMerge = objSourceDocument.MailMerge
' using the new mailmerge object ...
With objMailMerge
.OpenHeaderSource strHeaderRecordFilename, wdOpenFormatText,
False, True
' use the temporary file we've just created as the word
mailmerge data source
.OpenDataSource strFieldValuesTempFilename, wdOpenFormatText,
False, True
' set the last record property of the data source
' (this means that the blank record we stuck on the end
' of the data records will not be displayed)
.DataSource.LastRecord = intTotalRealRecords + 1
' execute the mailmerge!
.Execute (True)
End With
' dereference mail merge object
Set objMailMerge = Nothing
' close the original source document (discarding changes)
objSourceDocument.Close (wdDoNotSaveChanges)
' dereference word document object
Set objSourceDocument = Nothing
End With
' ---------------------------------------------------------
Debugging has told me that it is the .OpenHeaderSource command which is
causing the dialog to open.
In the above code the strHeaderRecordFilename variable is the path &
filename of a text document which holds the merge field names. The data
records are held in a text file for which the strFieldValuesTempFilename
variable holds the path & filename.
Does anyone have any suggestions?
Matt