B
Benjamino5
Hi all,
I'm working on a project that loops through this chunk of code dozens or
hundreds of times, and it's taking a long time to complete. Any ideas about
how to do this faster? I'm merging each row in the table and then calling a
find and replace operation in certain circumstances. Here's the code.
(By the way, the reason I'm declaring everything as a generic object is that
this code is inside a VB.Net project that late-binds to Word. That's another
slow-down: when this code runs inside an instance of Word instead of calling
Word through automation, it's much faster. But I have to keep my project in
VB.Net, )
_______________________
Sub MergeTable(ByRef oTable As Object)
' merge all cells on each row together
' then handle one of the following situations:
' 1) the row is NOT metadata, so replace the first para mark (put in
by merging) with a tab
' 2) the row is metadata, and originally "Ans:X" was in its own
cell, so there's no para mark
' to worry about removing (the next metadata field will have been
put on its own line, but that's
' what we want
' 3) the row is metadata, but the file was set up so that "Ans:" was
its own cell; so we need
' to remove the first para mark so "Ans:" and the answer are
together on the same line
Dim i As Integer
With oTable
For i = 1 To .rows.count
.rows(i).Cells.Merge()
' chr(13) is a para mark
' if the row has "Ans:[para mark]" or DOESN'T have "Ans:" at
all, then call ParaMarkToTab
If InStr(.rows.item(i).range.text, "Ans:" & Chr(13)) <> 0 Or
InStr(.rows.item(i).range.text, "Ans:") = 0 Then
Call ParaMarkToTab(.rows.item(i).Cells.item(1))
End If
Next i
End With
End Sub
Sub ParaMarkToTab(ByRef oCell As Object)
' turns the extra paragraph mark made when merging cells into a tab
' it stops after the first one, so it won't mess up any existing
paragraph marks
oCell.range.Find.Execute(FindText:="^p", Replacewith:="^t")
End Sub
I'm working on a project that loops through this chunk of code dozens or
hundreds of times, and it's taking a long time to complete. Any ideas about
how to do this faster? I'm merging each row in the table and then calling a
find and replace operation in certain circumstances. Here's the code.
(By the way, the reason I'm declaring everything as a generic object is that
this code is inside a VB.Net project that late-binds to Word. That's another
slow-down: when this code runs inside an instance of Word instead of calling
Word through automation, it's much faster. But I have to keep my project in
VB.Net, )
_______________________
Sub MergeTable(ByRef oTable As Object)
' merge all cells on each row together
' then handle one of the following situations:
' 1) the row is NOT metadata, so replace the first para mark (put in
by merging) with a tab
' 2) the row is metadata, and originally "Ans:X" was in its own
cell, so there's no para mark
' to worry about removing (the next metadata field will have been
put on its own line, but that's
' what we want
' 3) the row is metadata, but the file was set up so that "Ans:" was
its own cell; so we need
' to remove the first para mark so "Ans:" and the answer are
together on the same line
Dim i As Integer
With oTable
For i = 1 To .rows.count
.rows(i).Cells.Merge()
' chr(13) is a para mark
' if the row has "Ans:[para mark]" or DOESN'T have "Ans:" at
all, then call ParaMarkToTab
If InStr(.rows.item(i).range.text, "Ans:" & Chr(13)) <> 0 Or
InStr(.rows.item(i).range.text, "Ans:") = 0 Then
Call ParaMarkToTab(.rows.item(i).Cells.item(1))
End If
Next i
End With
End Sub
Sub ParaMarkToTab(ByRef oCell As Object)
' turns the extra paragraph mark made when merging cells into a tab
' it stops after the first one, so it won't mess up any existing
paragraph marks
oCell.range.Find.Execute(FindText:="^p", Replacewith:="^t")
End Sub