Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
Word
application.errors
conversions
docmanagement
drawing.graphics
formatting.longdocs
international
internet.assistant
mail
mailmerge.fields
menustoolbars
newusers
numbering
oleinterop
pagelayout
printingfonts
setup.networking
spelling.grammar
tables
vba.addins
vba.beginners
vba.customization
vba.general
vba.userforms
web.authoring
word6-7macros
word97vba
  
 
date: Tue, 12 Aug 2008 03:54:00 -0700,    group: microsoft.public.word.vba.general        back       


Find and replace very slow   
I've vrite code below to find and replace words in MSWord.
I've installed my application in a lot of PC and all works fine.
I've 2 PC with Win XP Pro and Office 200 Pro where this code run extremly 
slow (minutes to replace 100 word).
When application run on this PC i see word and it is slow but if i click on 
word window immedialy become fast. Help pls

The Code:
Private Sub Comando0_Click()
    Dim WordApp As Word.Application
    Set WordApp = New Word.Application
    WordApp.Visible = True
    Dim WordDoc As Word.Document
    Set WordDoc = WordApp.Documents.Open("C:\TimeTest\doc2.doc")
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    Dim i As Integer
    For i = 0 To 100
        Dim strFind As String
        Dim strReplace As String
        strFind = "Campo" & i + 1
        strReplace = "Campo" & i + 2
        With Selection.Find
            .Text = strFind
            .Replacement.Text = strReplace
            .Forward = True
            .Wrap = wdFindContinue
            .Format = False
            .MatchCase = False
            .MatchWholeWord = False
            .MatchWildcards = False
            .MatchSoundsLike = False
            .MatchAllWordForms = False
        End With
        Selection.Find.Execute Replace:=wdReplaceAll
    Next
    MsgBox "OK"
End Sub
date: Tue, 12 Aug 2008 03:54:00 -0700   author:   MNT77

Re: Find and replace very slow   
When i = 0

FindString = campo1  replacestring = campo2

When i = 1

FindSting = Campo2  replac string = campo3

So you are then replacing what was campo1 originally with campo3

and so on.

Instead, try using

For i = 100 to 0 step -1

That way, things will only be replaced one time
-- 
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

"MNT77"  wrote in message 
news:784389FB-C2CB-459D-8AF9-7CF58F01F53B@microsoft.com...
> I've vrite code below to find and replace words in MSWord.
> I've installed my application in a lot of PC and all works fine.
> I've 2 PC with Win XP Pro and Office 200 Pro where this code run extremly
> slow (minutes to replace 100 word).
> When application run on this PC i see word and it is slow but if i click 
> on
> word window immedialy become fast. Help pls
>
> The Code:
> Private Sub Comando0_Click()
>    Dim WordApp As Word.Application
>    Set WordApp = New Word.Application
>    WordApp.Visible = True
>    Dim WordDoc As Word.Document
>    Set WordDoc = WordApp.Documents.Open("C:\TimeTest\doc2.doc")
>    Selection.Find.ClearFormatting
>    Selection.Find.Replacement.ClearFormatting
>    Dim i As Integer
>    For i = 0 To 100
>        Dim strFind As String
>        Dim strReplace As String
>        strFind = "Campo" & i + 1
>        strReplace = "Campo" & i + 2
>        With Selection.Find
>            .Text = strFind
>            .Replacement.Text = strReplace
>            .Forward = True
>            .Wrap = wdFindContinue
>            .Format = False
>            .MatchCase = False
>            .MatchWholeWord = False
>            .MatchWildcards = False
>            .MatchSoundsLike = False
>            .MatchAllWordForms = False
>        End With
>        Selection.Find.Execute Replace:=wdReplaceAll
>    Next
>    MsgBox "OK"
> End Sub
date: Tue, 12 Aug 2008 21:03:27 +1000   author:   Doug Robbins - Word MVP

Re: Find and replace very slow   
This code is just to test time for doing find and replace.
Normally it takes 3/5 seconds to replace "Campo1" to "Campo2" to ... 
"Campo100"
In case of this 2 PC this scripts take 7 minutes!!! but if i click on word's 
window during process then it speed up to normally speed. I want to know why 
it speed up only if i click on word's window ?

"Doug Robbins - Word MVP" wrote:

> When i = 0
> 
> FindString = campo1  replacestring = campo2
> 
> When i = 1
> 
> FindSting = Campo2  replac string = campo3
> 
> So you are then replacing what was campo1 originally with campo3
> 
> and so on.
> 
> Instead, try using
> 
> For i = 100 to 0 step -1
> 
> That way, things will only be replaced one time
> -- 
> Hope this helps.
> 
> Please reply to the newsgroup unless you wish to avail yourself of my
> services on a paid consulting basis.
> 
> Doug Robbins - Word MVP
> 
> "MNT77"  wrote in message 
> news:784389FB-C2CB-459D-8AF9-7CF58F01F53B@microsoft.com...
> > I've vrite code below to find and replace words in MSWord.
> > I've installed my application in a lot of PC and all works fine.
> > I've 2 PC with Win XP Pro and Office 200 Pro where this code run extremly
> > slow (minutes to replace 100 word).
> > When application run on this PC i see word and it is slow but if i click 
> > on
> > word window immedialy become fast. Help pls
> >
> > The Code:
> > Private Sub Comando0_Click()
> >    Dim WordApp As Word.Application
> >    Set WordApp = New Word.Application
> >    WordApp.Visible = True
> >    Dim WordDoc As Word.Document
> >    Set WordDoc = WordApp.Documents.Open("C:\TimeTest\doc2.doc")
> >    Selection.Find.ClearFormatting
> >    Selection.Find.Replacement.ClearFormatting
> >    Dim i As Integer
> >    For i = 0 To 100
> >        Dim strFind As String
> >        Dim strReplace As String
> >        strFind = "Campo" & i + 1
> >        strReplace = "Campo" & i + 2
> >        With Selection.Find
> >            .Text = strFind
> >            .Replacement.Text = strReplace
> >            .Forward = True
> >            .Wrap = wdFindContinue
> >            .Format = False
> >            .MatchCase = False
> >            .MatchWholeWord = False
> >            .MatchWildcards = False
> >            .MatchSoundsLike = False
> >            .MatchAllWordForms = False
> >        End With
> >        Selection.Find.Execute Replace:=wdReplaceAll
> >    Next
> >    MsgBox "OK"
> > End Sub 
> 
> 
>
date: Tue, 12 Aug 2008 04:14:01 -0700   author:   MNT77

Re: Find and replace very slow   
I cannot explain the speed increase, but re-declaring the variables each 
time is not going to help.

Try the following

Dim i As Long
For i = 0 To 100
    Selection.HomeKey wdStory
    With Selection.Find
        .Text = "Campo" & i + 1
        .Replacement.Text = "Campo" & i + 2
        .Execute Replace:=wdReplaceAll
    End With
Next i

I am not sure whether you are starting with Campo1 just one time or 100 
times, but that change doesn't make much difference here
-- 
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

"MNT77"  wrote in message 
news:C1626BA4-5B2E-40D4-A12E-CAB0FE393D6B@microsoft.com...
> This code is just to test time for doing find and replace.
> Normally it takes 3/5 seconds to replace "Campo1" to "Campo2" to ...
> "Campo100"
> In case of this 2 PC this scripts take 7 minutes!!! but if i click on 
> word's
> window during process then it speed up to normally speed. I want to know 
> why
> it speed up only if i click on word's window ?
>
> "Doug Robbins - Word MVP" wrote:
>
>> When i = 0
>>
>> FindString = campo1  replacestring = campo2
>>
>> When i = 1
>>
>> FindSting = Campo2  replac string = campo3
>>
>> So you are then replacing what was campo1 originally with campo3
>>
>> and so on.
>>
>> Instead, try using
>>
>> For i = 100 to 0 step -1
>>
>> That way, things will only be replaced one time
>> -- 
>> Hope this helps.
>>
>> Please reply to the newsgroup unless you wish to avail yourself of my
>> services on a paid consulting basis.
>>
>> Doug Robbins - Word MVP
>>
>> "MNT77"  wrote in message
>> news:784389FB-C2CB-459D-8AF9-7CF58F01F53B@microsoft.com...
>> > I've vrite code below to find and replace words in MSWord.
>> > I've installed my application in a lot of PC and all works fine.
>> > I've 2 PC with Win XP Pro and Office 200 Pro where this code run 
>> > extremly
>> > slow (minutes to replace 100 word).
>> > When application run on this PC i see word and it is slow but if i 
>> > click
>> > on
>> > word window immedialy become fast. Help pls
>> >
>> > The Code:
>> > Private Sub Comando0_Click()
>> >    Dim WordApp As Word.Application
>> >    Set WordApp = New Word.Application
>> >    WordApp.Visible = True
>> >    Dim WordDoc As Word.Document
>> >    Set WordDoc = WordApp.Documents.Open("C:\TimeTest\doc2.doc")
>> >    Selection.Find.ClearFormatting
>> >    Selection.Find.Replacement.ClearFormatting
>> >    Dim i As Integer
>> >    For i = 0 To 100
>> >        Dim strFind As String
>> >        Dim strReplace As String
>> >        strFind = "Campo" & i + 1
>> >        strReplace = "Campo" & i + 2
>> >        With Selection.Find
>> >            .Text = strFind
>> >            .Replacement.Text = strReplace
>> >            .Forward = True
>> >            .Wrap = wdFindContinue
>> >            .Format = False
>> >            .MatchCase = False
>> >            .MatchWholeWord = False
>> >            .MatchWildcards = False
>> >            .MatchSoundsLike = False
>> >            .MatchAllWordForms = False
>> >        End With
>> >        Selection.Find.Execute Replace:=wdReplaceAll
>> >    Next
>> >    MsgBox "OK"
>> > End Sub
>>
>>
>>
date: Wed, 13 Aug 2008 07:16:58 +1000   author:   Doug Robbins - Word MVP

Re: Find and replace very slow   
redeclaring vars take time but i'm talking about minutes to find and replace 
a word in a simple document 100 times. And when i click (or simple move mouse 
on document) speed rapidly increase to normal (3 sec to complete)

I wrote code as access module and as vb.net exe application but in all 2 
enviornment problem is present... I can't find reason...

"Doug Robbins - Word MVP" wrote:

> I cannot explain the speed increase, but re-declaring the variables each 
> time is not going to help.
> 
> Try the following
> 
> Dim i As Long
> For i = 0 To 100
>     Selection.HomeKey wdStory
>     With Selection.Find
>         .Text = "Campo" & i + 1
>         .Replacement.Text = "Campo" & i + 2
>         .Execute Replace:=wdReplaceAll
>     End With
> Next i
> 
> I am not sure whether you are starting with Campo1 just one time or 100 
> times, but that change doesn't make much difference here
> -- 
> Hope this helps.
> 
> Please reply to the newsgroup unless you wish to avail yourself of my
> services on a paid consulting basis.
> 
> Doug Robbins - Word MVP
> 
> "MNT77"  wrote in message 
> news:C1626BA4-5B2E-40D4-A12E-CAB0FE393D6B@microsoft.com...
> > This code is just to test time for doing find and replace.
> > Normally it takes 3/5 seconds to replace "Campo1" to "Campo2" to ...
> > "Campo100"
> > In case of this 2 PC this scripts take 7 minutes!!! but if i click on 
> > word's
> > window during process then it speed up to normally speed. I want to know 
> > why
> > it speed up only if i click on word's window ?
> >
> > "Doug Robbins - Word MVP" wrote:
> >
> >> When i = 0
> >>
> >> FindString = campo1  replacestring = campo2
> >>
> >> When i = 1
> >>
> >> FindSting = Campo2  replac string = campo3
> >>
> >> So you are then replacing what was campo1 originally with campo3
> >>
> >> and so on.
> >>
> >> Instead, try using
> >>
> >> For i = 100 to 0 step -1
> >>
> >> That way, things will only be replaced one time
> >> -- 
> >> Hope this helps.
> >>
> >> Please reply to the newsgroup unless you wish to avail yourself of my
> >> services on a paid consulting basis.
> >>
> >> Doug Robbins - Word MVP
> >>
> >> "MNT77"  wrote in message
> >> news:784389FB-C2CB-459D-8AF9-7CF58F01F53B@microsoft.com...
> >> > I've vrite code below to find and replace words in MSWord.
> >> > I've installed my application in a lot of PC and all works fine.
> >> > I've 2 PC with Win XP Pro and Office 200 Pro where this code run 
> >> > extremly
> >> > slow (minutes to replace 100 word).
> >> > When application run on this PC i see word and it is slow but if i 
> >> > click
> >> > on
> >> > word window immedialy become fast. Help pls
> >> >
> >> > The Code:
> >> > Private Sub Comando0_Click()
> >> >    Dim WordApp As Word.Application
> >> >    Set WordApp = New Word.Application
> >> >    WordApp.Visible = True
> >> >    Dim WordDoc As Word.Document
> >> >    Set WordDoc = WordApp.Documents.Open("C:\TimeTest\doc2.doc")
> >> >    Selection.Find.ClearFormatting
> >> >    Selection.Find.Replacement.ClearFormatting
> >> >    Dim i As Integer
> >> >    For i = 0 To 100
> >> >        Dim strFind As String
> >> >        Dim strReplace As String
> >> >        strFind = "Campo" & i + 1
> >> >        strReplace = "Campo" & i + 2
> >> >        With Selection.Find
> >> >            .Text = strFind
> >> >            .Replacement.Text = strReplace
> >> >            .Forward = True
> >> >            .Wrap = wdFindContinue
> >> >            .Format = False
> >> >            .MatchCase = False
> >> >            .MatchWholeWord = False
> >> >            .MatchWildcards = False
> >> >            .MatchSoundsLike = False
> >> >            .MatchAllWordForms = False
> >> >        End With
> >> >        Selection.Find.Execute Replace:=wdReplaceAll
> >> >    Next
> >> >    MsgBox "OK"
> >> > End Sub
> >>
> >>
> >> 
> 
> 
>
date: Wed, 13 Aug 2008 04:55:01 -0700   author:   MNT77

Re: Find and replace very slow   
Here, using a document in which Campo1 appears 100 times, using that code is 
almost instanteous.   That's 10,000 replacements.

Of course, I am just doing it all in Word, not from another application.

-- 
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

"MNT77"  wrote in message 
news:87673568-7D83-4A04-A855-F45FEDBE43C8@microsoft.com...
> redeclaring vars take time but i'm talking about minutes to find and 
> replace
> a word in a simple document 100 times. And when i click (or simple move 
> mouse
> on document) speed rapidly increase to normal (3 sec to complete)
>
> I wrote code as access module and as vb.net exe application but in all 2
> enviornment problem is present... I can't find reason...
>
> "Doug Robbins - Word MVP" wrote:
>
>> I cannot explain the speed increase, but re-declaring the variables each
>> time is not going to help.
>>
>> Try the following
>>
>> Dim i As Long
>> For i = 0 To 100
>>     Selection.HomeKey wdStory
>>     With Selection.Find
>>         .Text = "Campo" & i + 1
>>         .Replacement.Text = "Campo" & i + 2
>>         .Execute Replace:=wdReplaceAll
>>     End With
>> Next i
>>
>> I am not sure whether you are starting with Campo1 just one time or 100
>> times, but that change doesn't make much difference here
>> -- 
>> Hope this helps.
>>
>> Please reply to the newsgroup unless you wish to avail yourself of my
>> services on a paid consulting basis.
>>
>> Doug Robbins - Word MVP
>>
>> "MNT77"  wrote in message
>> news:C1626BA4-5B2E-40D4-A12E-CAB0FE393D6B@microsoft.com...
>> > This code is just to test time for doing find and replace.
>> > Normally it takes 3/5 seconds to replace "Campo1" to "Campo2" to ...
>> > "Campo100"
>> > In case of this 2 PC this scripts take 7 minutes!!! but if i click on
>> > word's
>> > window during process then it speed up to normally speed. I want to 
>> > know
>> > why
>> > it speed up only if i click on word's window ?
>> >
>> > "Doug Robbins - Word MVP" wrote:
>> >
>> >> When i = 0
>> >>
>> >> FindString = campo1  replacestring = campo2
>> >>
>> >> When i = 1
>> >>
>> >> FindSting = Campo2  replac string = campo3
>> >>
>> >> So you are then replacing what was campo1 originally with campo3
>> >>
>> >> and so on.
>> >>
>> >> Instead, try using
>> >>
>> >> For i = 100 to 0 step -1
>> >>
>> >> That way, things will only be replaced one time
>> >> -- 
>> >> Hope this helps.
>> >>
>> >> Please reply to the newsgroup unless you wish to avail yourself of my
>> >> services on a paid consulting basis.
>> >>
>> >> Doug Robbins - Word MVP
>> >>
>> >> "MNT77"  wrote in message
>> >> news:784389FB-C2CB-459D-8AF9-7CF58F01F53B@microsoft.com...
>> >> > I've vrite code below to find and replace words in MSWord.
>> >> > I've installed my application in a lot of PC and all works fine.
>> >> > I've 2 PC with Win XP Pro and Office 200 Pro where this code run
>> >> > extremly
>> >> > slow (minutes to replace 100 word).
>> >> > When application run on this PC i see word and it is slow but if i
>> >> > click
>> >> > on
>> >> > word window immedialy become fast. Help pls
>> >> >
>> >> > The Code:
>> >> > Private Sub Comando0_Click()
>> >> >    Dim WordApp As Word.Application
>> >> >    Set WordApp = New Word.Application
>> >> >    WordApp.Visible = True
>> >> >    Dim WordDoc As Word.Document
>> >> >    Set WordDoc = WordApp.Documents.Open("C:\TimeTest\doc2.doc")
>> >> >    Selection.Find.ClearFormatting
>> >> >    Selection.Find.Replacement.ClearFormatting
>> >> >    Dim i As Integer
>> >> >    For i = 0 To 100
>> >> >        Dim strFind As String
>> >> >        Dim strReplace As String
>> >> >        strFind = "Campo" & i + 1
>> >> >        strReplace = "Campo" & i + 2
>> >> >        With Selection.Find
>> >> >            .Text = strFind
>> >> >            .Replacement.Text = strReplace
>> >> >            .Forward = True
>> >> >            .Wrap = wdFindContinue
>> >> >            .Format = False
>> >> >            .MatchCase = False
>> >> >            .MatchWholeWord = False
>> >> >            .MatchWildcards = False
>> >> >            .MatchSoundsLike = False
>> >> >            .MatchAllWordForms = False
>> >> >        End With
>> >> >        Selection.Find.Execute Replace:=wdReplaceAll
>> >> >    Next
>> >> >    MsgBox "OK"
>> >> > End Sub
>> >>
>> >>
>> >>
>>
>>
>>
date: Thu, 14 Aug 2008 05:46:01 +1000   author:   Doug Robbins - Word MVP

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us