View Single Post
  #1   Report Post  
ralf
 
Posts: n/a
Default Removing redundant characters

Hi!

I'm trying to remove all redundant characters like two many spaces or
paragraph signs from a word doc.
This is my code so far:

Dim wdApp As Word.Application
Dim wdDatei As Word.Document
Try
wdApp = New Word.Application
wdDatei = wdApp.Documents.Open(txtSource.Text)
Catch ex As Exception
MessageBox.Show(ex.Message)
Exit Sub
End Try
Try
With wdDatei.Range.Find
.Text = "^13^13"
.Replacement.Text = "^p"
.Forward = True
.Wrap = Word.WdFindWrap.wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
wdDatei.Range.Find.Execute(Replace:=Word.WdReplace .wdReplaceAll)
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
wdDatei.SaveAs(txtTarget.Text)
wdDatei.Close(Word.WdSaveOptions.wdDoNotSaveChange s)
wdApp.Quit()
wdDatei = Nothing
wdApp = Nothing
End Try´

When it gets to line
..Text = "^13^13"
it throws an exception.

I'm using Word 2000 and the Microsoft Word 9.0 Object Library.
Can anybody tell me what I'm doing wrong?
ralf