L
liu_jz
I wrote a program in VB6. I want to copy some rows in a table, and
paste many times (according to the record number). The program works
fine. But it is slow. How to speed up it?
Thanks advance.
Liu Jianzhong
Dim gwdApp As Word.Application
Dim gwdDoc As Word.Document
Dim gwdTable As Word.Table
Dim vntFieldValue() As Variant
Dim lngRangeBeginRow As Long
Dim lngRangeEndRow As Long
Dim lngStep As Long
Dim lngRecordCnt As Long
Dim i As Long
Dim j As Integer
.......
ReDim vntFieldValue(lngRecordCnt - 1, lngFieldCnt - 1)
.......
lngStep = lngRangeEndRow - lngRangeBeginRow + 1
With gwdApp.Selection
gwdDoc.Range(gwdTable.Rows(lngRangeBeginRow).Range.Start,
gwdTable.Rows(lngRangeEndRow).Range.End).Copy
lngTempPos = gwdTable.Cell(lngRangeBeginRow, 1).Range.Start
.SetRange lngTempPos, lngTempPos
For i = 0 To lngRecordCnt - 1
.Paste
Next i
End With
For i = 0 To lngRecordCnt - 1
For j = 0 To lngFieldCnt - 1
gwdTable.Cell(lngRow(j) + i * lngStep, lngCol(j)).Range.Text =
vntFieldValue(i, j)
Next j
Next i
paste many times (according to the record number). The program works
fine. But it is slow. How to speed up it?
Thanks advance.
Liu Jianzhong
Dim gwdApp As Word.Application
Dim gwdDoc As Word.Document
Dim gwdTable As Word.Table
Dim vntFieldValue() As Variant
Dim lngRangeBeginRow As Long
Dim lngRangeEndRow As Long
Dim lngStep As Long
Dim lngRecordCnt As Long
Dim i As Long
Dim j As Integer
.......
ReDim vntFieldValue(lngRecordCnt - 1, lngFieldCnt - 1)
.......
lngStep = lngRangeEndRow - lngRangeBeginRow + 1
With gwdApp.Selection
gwdDoc.Range(gwdTable.Rows(lngRangeBeginRow).Range.Start,
gwdTable.Rows(lngRangeEndRow).Range.End).Copy
lngTempPos = gwdTable.Cell(lngRangeBeginRow, 1).Range.Start
.SetRange lngTempPos, lngTempPos
For i = 0 To lngRecordCnt - 1
.Paste
Next i
End With
For i = 0 To lngRecordCnt - 1
For j = 0 To lngFieldCnt - 1
gwdTable.Cell(lngRow(j) + i * lngStep, lngCol(j)).Range.Text =
vntFieldValue(i, j)
Next j
Next i