J
jvbeaupre
I'm trying to transfer a thinned set of data from one document to
another using the code below. Typically np= 500000 and nmod = 400. I've
noticed that as the loop progresses it takes longer and longer (and
longer) to transfer a paragraph.
Any ideas on how to speed up the process?
For ip = 1 To np Step nmod
qq = Documents(q1).Paragraphs(ip).Range.Text
Documents(q2).Content.InsertAfter qq
Debug.Print 1 + Int(ip / nmod), ip
Next ip
Thanks,
Jim
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
The whole program is as follows:
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Sub thin()
Dim np As Long, ip As Long
Dialogs(wdDialogFileOpen).Show
q1 = ActiveDocument.Name
q2 = Left(q1, InStr(q1, ".") - 1) & "_THIN.txt"
Call newTextFile(q2)
np = Documents(q1).Paragraphs.Count
nmod = 400
Debug.Print "-----------------------------------------------"
Debug.Print np, nmod, Documents(q1).Name
Debug.Print "-----------------------------------------------"
Documents(q2).ActiveWindow.Visible = False
Documents(q1).ActiveWindow.Visible = False
For ip = 1 To np Step nmod
qq = Documents(q1).Paragraphs(ip).Range.Text
Documents(q2).Content.InsertAfter qq
Debug.Print 1 + Int(ip / nmod), ip
Next ip
np = Documents(q2).Paragraphs.Count
Debug.Print "-----------------------------------------------"
Debug.Print np, nmod, Documents(q2).Name
Debug.Print "-----------------------------------------------"
Documents(q1).ActiveWindow.Visible = True
Documents(q2).ActiveWindow.Visible = True
End Sub
Sub newTextFile(q2)
'
' newTextFile Macro
' Macro recorded 11/25/2006 by beauprej
'
Documents.Add Template:="Normal", NewTemplate:=False,
DocumentType:=0
ActiveDocument.SaveAs FileName:=q2, FileFormat:=wdFormatText, _
LockComments:=False, Password:="", AddToRecentFiles:=True,
WritePassword _
:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:=False, _
SaveNativePictureFormat:=False, SaveFormsData:=False,
SaveAsAOCELetter:= _
False, Encoding:=1252, InsertLineBreaks:=False,
AllowSubstitutions:=False _
, LineEnding:=wdCRLF
End Sub
another using the code below. Typically np= 500000 and nmod = 400. I've
noticed that as the loop progresses it takes longer and longer (and
longer) to transfer a paragraph.
Any ideas on how to speed up the process?
For ip = 1 To np Step nmod
qq = Documents(q1).Paragraphs(ip).Range.Text
Documents(q2).Content.InsertAfter qq
Debug.Print 1 + Int(ip / nmod), ip
Next ip
Thanks,
Jim
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
The whole program is as follows:
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Sub thin()
Dim np As Long, ip As Long
Dialogs(wdDialogFileOpen).Show
q1 = ActiveDocument.Name
q2 = Left(q1, InStr(q1, ".") - 1) & "_THIN.txt"
Call newTextFile(q2)
np = Documents(q1).Paragraphs.Count
nmod = 400
Debug.Print "-----------------------------------------------"
Debug.Print np, nmod, Documents(q1).Name
Debug.Print "-----------------------------------------------"
Documents(q2).ActiveWindow.Visible = False
Documents(q1).ActiveWindow.Visible = False
For ip = 1 To np Step nmod
qq = Documents(q1).Paragraphs(ip).Range.Text
Documents(q2).Content.InsertAfter qq
Debug.Print 1 + Int(ip / nmod), ip
Next ip
np = Documents(q2).Paragraphs.Count
Debug.Print "-----------------------------------------------"
Debug.Print np, nmod, Documents(q2).Name
Debug.Print "-----------------------------------------------"
Documents(q1).ActiveWindow.Visible = True
Documents(q2).ActiveWindow.Visible = True
End Sub
Sub newTextFile(q2)
'
' newTextFile Macro
' Macro recorded 11/25/2006 by beauprej
'
Documents.Add Template:="Normal", NewTemplate:=False,
DocumentType:=0
ActiveDocument.SaveAs FileName:=q2, FileFormat:=wdFormatText, _
LockComments:=False, Password:="", AddToRecentFiles:=True,
WritePassword _
:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:=False, _
SaveNativePictureFormat:=False, SaveFormsData:=False,
SaveAsAOCELetter:= _
False, Encoding:=1252, InsertLineBreaks:=False,
AllowSubstitutions:=False _
, LineEnding:=wdCRLF
End Sub