K
KitCaz
I'm using an MS Access VB script to create a document from a merge template
and to jump to a specific section to build a table of contents.
When I run the code the first time in an Access session, it works just fine.
But if I run the code a second time, my range selections register the
following error instead of valid values: <The remote server machine does not
exist or is unavailable>
I'm setting my WordApp, TOC and MyRange objects to nothing at the end of the
routine and quitting Word, but something residual is hosing up my subsequent
executions. What's up? It's always fine after I close Access and restart,
but I just get one shot each session.
Code fragment:
'create TOC, added 3/2005 cdc
Dim MyTOC As TablesOfContents
Dim myRange As Range
With wordApp.ActiveDocument
Set myRange = wordApp.ActiveDocument.Content
myRange.Find.Execute FindText:="Table Of Contents"
myRange.Goto what:=wdGoToLine, which:=wdGoToNext, Count:=2
Selection.Find.Execute FindText:="Table Of Contents"
Selection.Goto what:=wdGoToLine, which:=wdGoToNext, Count:=2
Set myRange = ActiveDocument.Range(Start:=Selection.Start,
End:=Selection.End)
ActiveDocument.TablesOfContents.Add Range:=myRange, _
UseFields:=False, UseHeadingStyles:=True, _
LowerHeadingLevel:=3, _
UpperHeadingLevel:=1
End With
(P.S. I'm having to do this at all because the TOC I had in the template
gets hosed after my programmatic merge. I posted this original problem but
no one volunteered any ideas, so I thought I'd try this.)
Thanks in advance,
Chris
and to jump to a specific section to build a table of contents.
When I run the code the first time in an Access session, it works just fine.
But if I run the code a second time, my range selections register the
following error instead of valid values: <The remote server machine does not
exist or is unavailable>
I'm setting my WordApp, TOC and MyRange objects to nothing at the end of the
routine and quitting Word, but something residual is hosing up my subsequent
executions. What's up? It's always fine after I close Access and restart,
but I just get one shot each session.
Code fragment:
'create TOC, added 3/2005 cdc
Dim MyTOC As TablesOfContents
Dim myRange As Range
With wordApp.ActiveDocument
Set myRange = wordApp.ActiveDocument.Content
myRange.Find.Execute FindText:="Table Of Contents"
myRange.Goto what:=wdGoToLine, which:=wdGoToNext, Count:=2
Selection.Find.Execute FindText:="Table Of Contents"
Selection.Goto what:=wdGoToLine, which:=wdGoToNext, Count:=2
Set myRange = ActiveDocument.Range(Start:=Selection.Start,
End:=Selection.End)
ActiveDocument.TablesOfContents.Add Range:=myRange, _
UseFields:=False, UseHeadingStyles:=True, _
LowerHeadingLevel:=3, _
UpperHeadingLevel:=1
End With
(P.S. I'm having to do this at all because the TOC I had in the template
gets hosed after my programmatic merge. I posted this original problem but
no one volunteered any ideas, so I thought I'd try this.)
Thanks in advance,
Chris