Works the second time its run. RPC Server is Unavailable

  • Thread starter Thread starter Nev
  • Start date Start date
N

Nev

Hi,
Im using vba code (see below) in access to perform a
replace in a word document from within access. the first
time i run the code i get the following error "Run-time
error '-2147023174 (800706ba)':
Automation error
The RPC Server is unavailable"

but then i can run it again and it works fine. does anyone
know why this might be happening and how i might resolve
it.

Thanks in advance,
Nev.


Function ModTabandChevReplacer()

Dim objWord As Word.Application
Set objWord = CreateObject("Word.Application")
Documents.Open FileName:="D:\Data\originalreplacer.rtf",
ConfirmConversions:=False _
, ReadOnly:=False, AddToRecentFiles:=False,
PasswordDocument:="", _
PasswordTemplate:="", Revert:=False,
WritePasswordDocument:="", _
WritePasswordTemplate:="", Format:=wdOpenFormatAuto

ActiveDocument.Select
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "^t"
.Replacement.Text = " "
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
ActiveDocument.Save
ActiveDocument.Close
Set objWord = Nothing
End Function
 
The variables "Documents", "ActiveDocument" and a host of others are not
being set anywhere, so this won't work.

Try doing

objword.Documents.Open FileName . . . . ..
objWord.Selection.Find . . . etc
 
Back
Top