B
Brent Whaling
I am using word to prepare a delimited file to be imported into Excel and am
having trouble getting rid of extra ^p characters.
Basically, starting with the second line of the file I need to remove all ^p
unless they are immediately followed by the date (ex. 04-NOV-2008). I've
figured out the pattern mask (^p^#^#-^$^$^$-20^#^#).
I was hoping to use "Find and Replace" code but I'm wondering how to create
the above exception. Maybe a properly place "if" statement or perhaps there
is a property of "Find" that I'm not aware of.
Any help would be much appreciated.
Until now I've been doing it this way but I keep finding more and more ^p
characters and I would like to implement a more elegant solution.
Dim wdApp As Word.Application, wdDoc As Word.Document
On Error Resume Next
Set wdApp = GetObject(, "Word.Application")
If Err.Number <> 0 Then 'Word isn't already running
Set wdApp = CreateObject("Word.Application")
End If
On Error GoTo 0
Set wdDoc = wdApp.Documents.Open("C:\temp\esi_monitor.dat")
wdApp.Visible = True
With wdDoc.Range.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = ".^p.^p"
.Replacement.Text = ".."
.Execute Replace:=wdReplaceAll
End With
With wdDoc.Range.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = "^p)"
.Replacement.Text = ")"
.Execute Replace:=wdReplaceAll
End With
With wdDoc.Range.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = "D^p@"
.Replacement.Text = "D@"
.Execute Replace:=wdReplaceAll
End With
With wdDoc.Range.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = "\@|"
.Replacement.Text = "\&|"
.Execute Replace:=wdReplaceAll
End With
wdDoc.SaveAs "C:\temp\esi_monitor.dat"
wdDoc.Close
wdApp.Quit
having trouble getting rid of extra ^p characters.
Basically, starting with the second line of the file I need to remove all ^p
unless they are immediately followed by the date (ex. 04-NOV-2008). I've
figured out the pattern mask (^p^#^#-^$^$^$-20^#^#).
I was hoping to use "Find and Replace" code but I'm wondering how to create
the above exception. Maybe a properly place "if" statement or perhaps there
is a property of "Find" that I'm not aware of.
Any help would be much appreciated.
Until now I've been doing it this way but I keep finding more and more ^p
characters and I would like to implement a more elegant solution.
Dim wdApp As Word.Application, wdDoc As Word.Document
On Error Resume Next
Set wdApp = GetObject(, "Word.Application")
If Err.Number <> 0 Then 'Word isn't already running
Set wdApp = CreateObject("Word.Application")
End If
On Error GoTo 0
Set wdDoc = wdApp.Documents.Open("C:\temp\esi_monitor.dat")
wdApp.Visible = True
With wdDoc.Range.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = ".^p.^p"
.Replacement.Text = ".."
.Execute Replace:=wdReplaceAll
End With
With wdDoc.Range.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = "^p)"
.Replacement.Text = ")"
.Execute Replace:=wdReplaceAll
End With
With wdDoc.Range.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = "D^p@"
.Replacement.Text = "D@"
.Execute Replace:=wdReplaceAll
End With
With wdDoc.Range.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = "\@|"
.Replacement.Text = "\&|"
.Execute Replace:=wdReplaceAll
End With
wdDoc.SaveAs "C:\temp\esi_monitor.dat"
wdDoc.Close
wdApp.Quit