R
Rod Scoullar
A VBA procedure that has worked in Office 2000 is failing when run in 2003.
The procedure uses automation to merge data from an Access database into a
Word file. Some of the data merged are themselves Word documents. These
require several fields merged following their insert. This has been
accomplished by using search and replace as a pseudo merge.
The included documents have name and ID code specified as <<Name>> and
<<ID>> and these are replaced following the merge by the appropriate values.
In 2003 merge succeeds but the search and replace fails. The Find object of
the Range object cannot be referenced and the Access application closes when
this is attempted.
Any help would be appreciated. The relevant VBA code is shown below.
Rod Scoullar
----------
Dim objWord As Object
Dim objAcc As Object
Dim strHold As String
Dim strName As String
Dim strPNum As String
objWord.Documents.Open (strDocName)
objWord.Visible = True
' do the merge
With objWord.ActiveDocument.MailMerge
.OpenDataSource Name:="C:\UHGLifetrack\LTMM.txt",
Format:=wdOpenFormatText, ConfirmConversions:=False
' save the name and id for use in the search and replace
strName = .DataSource.DataFields("PatientFirstName").Value & " " &
..DataSource.DataFields("PatientLastName").Value
strPNum = .DataSource.DataFields("PolicyNumber").Value
.Destination = wdSendToNewDocument
.SuppressBlankLines = True
.Execute
End With
objWord.ActiveDocument.Select
objWord.Selection.Fields.Update
objWord.Selection.Collapse
' set range object to point to document content
Dim rng As Range
Set rng = objWord.ActiveDocument.Content
**** rng.Find.Text = "<<Name>>" **** fails at this point
rng.Find.Replacement.Text = strName
rng.Find.Execute Replace:=wdReplaceAll
The procedure uses automation to merge data from an Access database into a
Word file. Some of the data merged are themselves Word documents. These
require several fields merged following their insert. This has been
accomplished by using search and replace as a pseudo merge.
The included documents have name and ID code specified as <<Name>> and
<<ID>> and these are replaced following the merge by the appropriate values.
In 2003 merge succeeds but the search and replace fails. The Find object of
the Range object cannot be referenced and the Access application closes when
this is attempted.
Any help would be appreciated. The relevant VBA code is shown below.
Rod Scoullar
----------
Dim objWord As Object
Dim objAcc As Object
Dim strHold As String
Dim strName As String
Dim strPNum As String
objWord.Documents.Open (strDocName)
objWord.Visible = True
' do the merge
With objWord.ActiveDocument.MailMerge
.OpenDataSource Name:="C:\UHGLifetrack\LTMM.txt",
Format:=wdOpenFormatText, ConfirmConversions:=False
' save the name and id for use in the search and replace
strName = .DataSource.DataFields("PatientFirstName").Value & " " &
..DataSource.DataFields("PatientLastName").Value
strPNum = .DataSource.DataFields("PolicyNumber").Value
.Destination = wdSendToNewDocument
.SuppressBlankLines = True
.Execute
End With
objWord.ActiveDocument.Select
objWord.Selection.Fields.Update
objWord.Selection.Collapse
' set range object to point to document content
Dim rng As Range
Set rng = objWord.ActiveDocument.Content
**** rng.Find.Text = "<<Name>>" **** fails at this point
rng.Find.Replacement.Text = strName
rng.Find.Execute Replace:=wdReplaceAll