Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsVB SyntaxEnterprise DevelopmentDatabase AccessControlsCOMWin APICrystal ReportDeploymentGeneralGeneral 2
Related Topics
VB.NET / ASP.NETMS SQL ServerMS AccessOther Database ProductsMore Topics ...

VB Forum / COM / March 2007



Tip: Looking for answers? Try searching our database.

Automating word - problems adding AutoTextEntries

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Simon Woods - 29 Mar 2007 08:35 GMT
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
Simon Woods - 29 Mar 2007 11:35 GMT
Sorted. My AutoTextEntry name wasn't unique!
Thanks

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
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.