S
Simon Woods
Hi
I'm automating Word from VB6, but I'm having problems adding AutoTextEntries programmatically. I've included the function I'm using below.
The code compiles and runs, but there are a couple things that don't work
1) I don't get any AutoTextEntries intellisense although I do get the AttachedTemplate as intellisense.
2) When I step the code, the object l_oAutoTextEntry gets set and I can inspect it in the Watch window. However, the AutoTextEntries.count does not increment and the collection does not appear to contain the new autotextentry
Can anyone give any pointers where I'm going wrong
Thanks
Simon
Private Function CreateAutoTextEntries(ByRef p_oDoc As Word.Document) As Long
Dim l_oStartRange As Word.Range
Dim l_oEndRange As Word.Range
Dim l_oAutoTextEntry As Word.AutoTextEntry
Dim l_bDone As Boolean
Dim i As Long
Dim l_nStartPos As Long
Dim l_nEndPos As Long
Dim l_nRes As Long
On Error GoTo ExitProc
l_nRes = C_FAILURE
Set l_oStartRange = p_oDoc.Content
Set l_oEndRange = p_oDoc.Content
Do Until l_bDone
p_oDoc.Content.Find.Execute C_BLOCK_START, Forward:=True
l_oStartRange.Find.Execute C_BLOCK_START, Forward:=True
If l_oStartRange.Find.Found Then
l_nStartPos = l_oStartRange.Start
Set l_oEndRange = p_oDoc.Range(l_oStartRange.Start)
l_oEndRange.Find.Execute C_BLOCK_END, Forward:=True
If l_oEndRange.Find.Found Then
If l_oEndRange.End > l_nStartPos Then
l_nEndPos = l_oEndRange.End
Set l_oAutoTextEntry = p_oDoc.AttachedTemplate.AutoTextEntries.Add("Label" & i, p_oDoc.Range(Start:=l_nStartPos, End:=l_nEndPos))
If l_oAutoTextEntry Is Nothing Then
Err.Raise 0
End If
i = i + 1
End If
Else
l_bDone = True
End If
Else
l_bDone = True
End If
Loop
l_nRes = C_SUCCESS
ExitProc:
CreateAutoTextEntries = l_nRes
End Function
I'm automating Word from VB6, but I'm having problems adding AutoTextEntries programmatically. I've included the function I'm using below.
The code compiles and runs, but there are a couple things that don't work
1) I don't get any AutoTextEntries intellisense although I do get the AttachedTemplate as intellisense.
2) When I step the code, the object l_oAutoTextEntry gets set and I can inspect it in the Watch window. However, the AutoTextEntries.count does not increment and the collection does not appear to contain the new autotextentry
Can anyone give any pointers where I'm going wrong
Thanks
Simon
Private Function CreateAutoTextEntries(ByRef p_oDoc As Word.Document) As Long
Dim l_oStartRange As Word.Range
Dim l_oEndRange As Word.Range
Dim l_oAutoTextEntry As Word.AutoTextEntry
Dim l_bDone As Boolean
Dim i As Long
Dim l_nStartPos As Long
Dim l_nEndPos As Long
Dim l_nRes As Long
On Error GoTo ExitProc
l_nRes = C_FAILURE
Set l_oStartRange = p_oDoc.Content
Set l_oEndRange = p_oDoc.Content
Do Until l_bDone
p_oDoc.Content.Find.Execute C_BLOCK_START, Forward:=True
l_oStartRange.Find.Execute C_BLOCK_START, Forward:=True
If l_oStartRange.Find.Found Then
l_nStartPos = l_oStartRange.Start
Set l_oEndRange = p_oDoc.Range(l_oStartRange.Start)
l_oEndRange.Find.Execute C_BLOCK_END, Forward:=True
If l_oEndRange.Find.Found Then
If l_oEndRange.End > l_nStartPos Then
l_nEndPos = l_oEndRange.End
Set l_oAutoTextEntry = p_oDoc.AttachedTemplate.AutoTextEntries.Add("Label" & i, p_oDoc.Range(Start:=l_nStartPos, End:=l_nEndPos))
If l_oAutoTextEntry Is Nothing Then
Err.Raise 0
End If
i = i + 1
End If
Else
l_bDone = True
End If
Else
l_bDone = True
End If
Loop
l_nRes = C_SUCCESS
ExitProc:
CreateAutoTextEntries = l_nRes
End Function