Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / October 2005

Tip: Looking for answers? Try searching our database.

How to speed up the program?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
liu_jz@yahoo.com - 14 Oct 2005 09:48 GMT
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
Jonathan West - 14 Oct 2005 14:04 GMT
1. Don't use the selection. This is very slow. Instead, define one or more
object variables of type Range and use those instead. You can so almost
anything with a Range object variable that you can do with the Selection
object.

2. Don't use the clipboard. If you are wanting to move unformatted text
around, You can read the Text property of a range and place it into a string
variable. You can then use the InsertAfter method to insert text after any
Range, or you can set the Text property of a Range to place text there
replacing existing text. If you want to move formatted text around retaining
the formatting, look at using the FormattedText property.

Signature

Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org

>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
[quoted text clipped - 33 lines]
>    Next j
> Next i
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.