C
Charles Kenyon
I have a complex problem using Word 2003. It may be in other versions, just
haven't tested. It involves a UserForm that interposes itself between two
merge dialogs when a new document is created.
I've got a discovery demand that I routinely use. It is a merge template
merging with an Excel spreadsheet. Creation of a new document based on the
template starts with a UserForm that allows modification for three different
types of cases. In one of those cases (DUI) the Cmd_OK_Click handler inserts
a number of AutoText entries at various locations in the document (noted by
bookmarks). This works fine for all of the entries except one that has merge
codes in it.
Those merge codes, themselves, include an IF field to test for a middle
initial.
This includes any videotape made of {MERGEFIELD Client_First }{MERGEFIELD
Client_MI }{ IF {MERGEFIELD Client_MI }= "" "" " " }{ MERGEFIELD
Client_Last } whether or not the government considers said video to be a
"statement."
The resulting text should be:
This includes any videotape made of First M. Last whether or not the
government considers said video to be a "statement."
or
This includes any videotape made of First Last whether or not the
government considers said video to be a "statement."
If I insert the AutoText entry manually, the codes show up and work with no
problem. But when I rely on the procedure I get the following instead:
This includes any videotape made of * MERGEFIELD Client_First *First* *
MERGEFIELD Client_MI *M.** IF * MERGEFIELD Client_MI *M.* = "" "" " " * **
MERGEFIELD Client_Last *Last* whether or not the government considers said
video to be a "statement."
None of this is fields, it is all hard text.
The code to insert works with all of the other AT items inserted (none of
which, I believe, contain merge codes). If I run a macro to insert the AT
entry in question in the existing document, it works fine.
To make it even quirkier, I have run it once (out of about 40 times) where
it properly inserted the fields. That time was just after I had run the
individual macro (in a different document) inserting the AT entry. I then
created a new document and it worked. Haven't been able to replicate it
working.
The relevant portion of the code inserting the AutoText is:
Dim BMRange As Range
Set BMRange = ActiveDocument.Bookmarks("BmDxDWI2").Range
BMRange.Text =
ActiveDocument.AttachedTemplate.AutoTextEntries("AtDxDWI2")
BMRange.Select
ActiveDocument.Bookmarks.Add "BmDxDWI2", BMRange
A recorded macro inserting the same AutoText entry at the selection point
works. It is:
Sub Macro4()
'
' Macro4 Macro
' Macro recorded 2/24/2004 by Charles Kyle Kenyon
'
Selection.GoTo What:=wdGoToBookmark, Name:="BmDxDWI2"
With ActiveDocument.Bookmarks
.DefaultSorting = wdSortByName
.ShowHidden = False
End With
Application.DisplayAutoCompleteTips = True
ActiveDocument.AttachedTemplate.AutoTextEntries("AtDxDWI2").Insert
Where:= _
Selection.Range, RichText:=True
Selection.MoveUp Unit:=wdLine, Count:=3, Extend:=wdExtend
Selection.MoveLeft Unit:=wdCharacter, Count:=4, Extend:=wdExtend
With ActiveDocument.Bookmarks
.Add Range:=Selection.Range, Name:="BmDxDWI2"
.DefaultSorting = wdSortByName
.ShowHidden = False
End With
Selection.HomeKey Unit:=wdLine
End Sub
Sorry for being so long and complex.
TIA
--
Charles Kenyon
See the MVP FAQ: <URL: http://www.mvps.org/word/> which is awesome!
--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.
haven't tested. It involves a UserForm that interposes itself between two
merge dialogs when a new document is created.
I've got a discovery demand that I routinely use. It is a merge template
merging with an Excel spreadsheet. Creation of a new document based on the
template starts with a UserForm that allows modification for three different
types of cases. In one of those cases (DUI) the Cmd_OK_Click handler inserts
a number of AutoText entries at various locations in the document (noted by
bookmarks). This works fine for all of the entries except one that has merge
codes in it.
Those merge codes, themselves, include an IF field to test for a middle
initial.
This includes any videotape made of {MERGEFIELD Client_First }{MERGEFIELD
Client_MI }{ IF {MERGEFIELD Client_MI }= "" "" " " }{ MERGEFIELD
Client_Last } whether or not the government considers said video to be a
"statement."
The resulting text should be:
This includes any videotape made of First M. Last whether or not the
government considers said video to be a "statement."
or
This includes any videotape made of First Last whether or not the
government considers said video to be a "statement."
If I insert the AutoText entry manually, the codes show up and work with no
problem. But when I rely on the procedure I get the following instead:
This includes any videotape made of * MERGEFIELD Client_First *First* *
MERGEFIELD Client_MI *M.** IF * MERGEFIELD Client_MI *M.* = "" "" " " * **
MERGEFIELD Client_Last *Last* whether or not the government considers said
video to be a "statement."
None of this is fields, it is all hard text.
The code to insert works with all of the other AT items inserted (none of
which, I believe, contain merge codes). If I run a macro to insert the AT
entry in question in the existing document, it works fine.
To make it even quirkier, I have run it once (out of about 40 times) where
it properly inserted the fields. That time was just after I had run the
individual macro (in a different document) inserting the AT entry. I then
created a new document and it worked. Haven't been able to replicate it
working.
The relevant portion of the code inserting the AutoText is:
Dim BMRange As Range
Set BMRange = ActiveDocument.Bookmarks("BmDxDWI2").Range
BMRange.Text =
ActiveDocument.AttachedTemplate.AutoTextEntries("AtDxDWI2")
BMRange.Select
ActiveDocument.Bookmarks.Add "BmDxDWI2", BMRange
A recorded macro inserting the same AutoText entry at the selection point
works. It is:
Sub Macro4()
'
' Macro4 Macro
' Macro recorded 2/24/2004 by Charles Kyle Kenyon
'
Selection.GoTo What:=wdGoToBookmark, Name:="BmDxDWI2"
With ActiveDocument.Bookmarks
.DefaultSorting = wdSortByName
.ShowHidden = False
End With
Application.DisplayAutoCompleteTips = True
ActiveDocument.AttachedTemplate.AutoTextEntries("AtDxDWI2").Insert
Where:= _
Selection.Range, RichText:=True
Selection.MoveUp Unit:=wdLine, Count:=3, Extend:=wdExtend
Selection.MoveLeft Unit:=wdCharacter, Count:=4, Extend:=wdExtend
With ActiveDocument.Bookmarks
.Add Range:=Selection.Range, Name:="BmDxDWI2"
.DefaultSorting = wdSortByName
.ShowHidden = False
End With
Selection.HomeKey Unit:=wdLine
End Sub
Sorry for being so long and complex.
TIA
--
Charles Kenyon
See the MVP FAQ: <URL: http://www.mvps.org/word/> which is awesome!
--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.