Need some VBA programming help with a Log File

J

jc

I have a .log file with lines and lines of data. I can open this log file in
Word but I need to do things to this file for me to be able to use it. A
line of text will start out with a space and then either CN## or TS##. If
the line starts with either one, then I want to go to the text in that line
and find PR10 and delete everything from the PR10 to the end of that line and
also delete the End Paragraph mark. I have searched other questions but have
not found a code that works for me. Also if someone has a good book or
documentation that would help me learn VBA that would be great. If it helps
at all this file is from a program called Advance Serial Data Logger and it
is logging pages to a Glenayre Paging Terminal.
 
D

Doug Robbins - Word MVP

This should do what you want:

Dim i As Long
Dim delrange As Range
With ActiveDocument
For i = .Paragraphs.Count To 1 Step -1
Set delrange = .Paragraphs(i).Range
With delrange
If Left(.Text, 5) = " CN##" Or Left(.Text, 5) = " TS##" Then
.Start = .Start + InStr(.Text, "PR10")
.Delete
End If
End With
Next i
End With


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
 

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