C
Conan Kelly
Hello all,
I'm working with plain text files of data that are in a report format: a new page after 60 (or so) lines of data with new page
headers & column headers on each new page along with summaries at the end of each section (8 or 9 sections). I need to chop out all
the summaries, page headers, footers, report headers, etc... so all I have is the data so that it can be imported into SQL Server.
I'm doing this in MS Word because I can use VBA to automate it.
I have the code to search for the category summaries and delete them. I want to keep these summaries, so I have code to write them
to another text file before deleting them.
The problem I'm having is that I would like to count the number of lines in these summaries that I'm moving/deleting.
I have come up with the following code:
Sub testCountLines()
Dim pintCounter As Integer
Dim pintIndex As Integer
Dim pdteStartTime As Date
Dim pdteEndTime As Date
Dim pdteRunTime As Date
pdteStartTime = Now()
pintCounter = 0
For pintIndex = 1 To Selection.Characters.Count
If Asc(Selection.Characters(pintIndex)) = 13 Then pintCounter = pintCounter + 1
' MsgBox "''" & Selection.Characters(pintIndex) & "''" & vbCrLf & Asc(Selection.Characters(pintIndex))
Next pintIndex
' MsgBox pintCounter
pdteEndTime = Now()
pdteRunTime = pdteEndTime - pdteStartTime
MsgBox Format(pdteRunTime, "hh:mm:ss") & vbCrLf _
& "Number of Characters: " & Selection.Characters.Count & vbCrLf _
& "Number of Lines: " & pintCounter
End Sub
The problem is that it took 3 mins 34 secs to loop through 5143 characters and count 49 lines.
Is there a faster way of doing this?
Keep in mind, yesterday someone suggested Selection.Range.ComputeStatistics(wdStatisticLines). But when I tried that, it returned
around 690 for what was actually 31 lines of text.
(These sections of these text files that I'm processing are aligned summary "Tables" (counts & sums) in the text files that are
aligned using spaces with a carriage return at the end of each line--that is why there is such a high character:lines ratio)
49 lines
5143 characters
00:03:34
I'm working with plain text files of data that are in a report format: a new page after 60 (or so) lines of data with new page
headers & column headers on each new page along with summaries at the end of each section (8 or 9 sections). I need to chop out all
the summaries, page headers, footers, report headers, etc... so all I have is the data so that it can be imported into SQL Server.
I'm doing this in MS Word because I can use VBA to automate it.
I have the code to search for the category summaries and delete them. I want to keep these summaries, so I have code to write them
to another text file before deleting them.
The problem I'm having is that I would like to count the number of lines in these summaries that I'm moving/deleting.
I have come up with the following code:
Sub testCountLines()
Dim pintCounter As Integer
Dim pintIndex As Integer
Dim pdteStartTime As Date
Dim pdteEndTime As Date
Dim pdteRunTime As Date
pdteStartTime = Now()
pintCounter = 0
For pintIndex = 1 To Selection.Characters.Count
If Asc(Selection.Characters(pintIndex)) = 13 Then pintCounter = pintCounter + 1
' MsgBox "''" & Selection.Characters(pintIndex) & "''" & vbCrLf & Asc(Selection.Characters(pintIndex))
Next pintIndex
' MsgBox pintCounter
pdteEndTime = Now()
pdteRunTime = pdteEndTime - pdteStartTime
MsgBox Format(pdteRunTime, "hh:mm:ss") & vbCrLf _
& "Number of Characters: " & Selection.Characters.Count & vbCrLf _
& "Number of Lines: " & pintCounter
End Sub
The problem is that it took 3 mins 34 secs to loop through 5143 characters and count 49 lines.
Is there a faster way of doing this?
Keep in mind, yesterday someone suggested Selection.Range.ComputeStatistics(wdStatisticLines). But when I tried that, it returned
around 690 for what was actually 31 lines of text.
(These sections of these text files that I'm processing are aligned summary "Tables" (counts & sums) in the text files that are
aligned using spaces with a carriage return at the end of each line--that is why there is such a high character:lines ratio)
49 lines
5143 characters
00:03:34