Access gets closed due to unknown error

N

navin

Hi,

From one of my forms, i open a word document and try to clear the junk
from it like some extra lines, words etc. this was working fine but
suddenly now whenever access opens the word file and tries to do
changes, Access quits after displaying "MS- Access as encountered a
problem and will close."

After i remove the word manipulation part of code, it works fine.
could somebody tell me why access quits when try to manipulate the
word file? Below is code:

Set wdApp = CreateObject("Word.Application")
sPDFName = "testPDF.pdf"
sPDFPath = "C:\PO Copies"
wdApp.Visible = True
Set wdDoc = wdApp.Documents.Open(fileName:=DocPath & DocName)
'Edit open word copy to clear the junk and format the document
wdDoc.Activate

Access quits after reaching this point.


' wdApp.Selection.Find.ClearFormatting
' With wdApp.Selection.Find
' .Text = "from"
' .Replacement.Text = ""
' .Forward = True
' .Wrap = wdFindContinue
' .Format = False
' .MatchCase = False
' .MatchWholeWord = False
' .MatchWildcards = False
' .MatchSoundsLike = False
' .MatchAllWordForms = False
' End With
' wdApp.Selection.Find.Execute
' wdApp.Selection.MoveLeft Unit:=wdCharacter, Count:=1
' wdApp.Selection.MoveDown Unit:=wdLine, Count:=4, Extend:=wdExtend
' wdApp.Selection.Delete Unit:=wdCharacter, Count:=1

'On Error Resume Next
' wdApp.Selection.PageSetup.LeftMargin = InchesToPoints(0.38)
' With wdApp.Selection.ParagraphFormat
' .RightIndent = InchesToPoints(-0.88)
' .SpaceBeforeAuto = False
' .SpaceAfterAuto = False
' End With

Please help.

thanks,
navin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top