Hi Shauna,
Thanks for the reply. I tried what you suggested and I still get the
message, "The requested member of the collection does not exist." I have
loaded the firm.dot in the correct default word startup directory, and Word
is pointing to this directory in the locations under tools/options.
My syntax now reads what you suggested:
If frmreplacepi.txtattyinitials = "agq" Then
Templates("firm.dot").AutoTextEntries("/agqpi").Insert _
Where:=Selection.Range, RichText:=True
I also tried this:
If frmreplacepi.txtattyinitials = "agq" Then
Set MyTemplate = Templates("firm.dot")
MyTemplate.AutoTextEntries("/agqpi").Insert _
Where:=Selection.Range, RichText:=True
That doesn't work either.
Any help? THANKS SO VERY MUCH!!
Kurt
> Hi Kurt
>
[quoted text clipped - 62 lines]
> >
> > Kurt
Shauna Kelly - 22 Jan 2008 03:43 GMT
Hi Kurt
What you have is a debugging problem. That is, you have to work out
where, exactly, the problem is occurring. Or in other words, you need to
be able to interpret the error message and find out which member of what
collection does not exist. You can largely achieve this by (1) clicking
on the first line of your code and pressing F9, which will put a break
point there, then (2) running the code and (3) when you get to that
break point, press F8 to go through the code line by line. When the
error message appears, you'll know which line you were on, and can thus
make some reasonable guesses as to the problem.
You might also consider writing code that is fireproof. Something like
this:
Sub Test1()
Dim atInitials As Word.AutoTextEntry
Dim sInitials As String
Dim tplFirm As Word.Template
If Not frmreplacepi Is Nothing Then
'Get the initials from the form
On Error Resume Next
sInitials = frmreplacepi.txtattyinitials
On Error GoTo 0
If sInitials = "agq" Then
'Get a reference to the template
On Error Resume Next
Set tplFirm = Templates("firm.dot")
On Error GoTo 0
If Not tplFirm Is Nothing Then
'Get a reference to the AutoText
On Error Resume Next
Set atInitials = tplFirm.AutoTextEntries("/agqpi")
On Error GoTo 0
If Not atInitials Is Nothing Then
'Insert the AutoText
atInitials.Insert Where:=Selection.Range,
RichText:=True
Else
MsgBox "There is no AutoText named '/agqpi' in
firm.dot"
End If
Else
MsgBox "Word can't find a template named firm.dot"
End If
Else
MsgBox "Initials do not equal agq"
End If
Else
MsgBox "frmreplacepi does not exist, so there is not much we can
do today"
End If
End Sub
I'm not suggesting that good code should end up with very deeply-nested
If / Else / Endif statements. But good code does need error checking.
Hope this helps.
Shauna Kelly. Microsoft MVP.
http://www.shaunakelly.com/word
> Hi Shauna,
>
[quoted text clipped - 99 lines]
>> >
>> > Kurt