Re: Very, very slow macro
- From: "John Svendsen" <jfs@xxxxxxxxxxxxx>
- Date: Tue, 8 Nov 2005 19:13:00 -0200
Hi Tony,
It's taken me sometime to come around... But I'd like to thank you for your
tips - I did not know that ==>^&<== repeated whatever was selected in the
Find box...
With this, things are now much easier.
Regards, JS
"Tony Jollans" <No Mail> wrote in message
news:erlg5Dq0FHA.1032@xxxxxxxxxxxxxxxxxxxxxxx
> I'm not a user of machine translation but I would have thought you were
> introducing translation problems by splitting sentences, but for what it's
> worth ...
>
> You can make the code a bit more efficient by using a With construct,
> something like this ..
>
> With Selection.Words(xxx)
> If .Bold And Not .Previous.Bold Or _
> Not .Bold And .Previous.Bold _
> Or _
> etc.
>
> But really it is still so painfully slow that I would be more inclined to
> simply do a search for all bold text and surround it with "\", then repeat
> for italic and underline (a little trickier). Then replace all multiple
> instances of the "\" character with one. It isn't perfect - but then what
> you're doing isn't either - but it can be done in real time :-)
>
> Using Find and Replace, set the Find format to Bold (and leave the box
> empty), and the Replace text to \^&\ (backslash, caret, ampersand,
> backslash)
> For underlining you need to select each style of uinderline separately
which
> is a bit painful if you use several styles (but no big deal in code I
> suppose). One point to note if you do this manually and record it to get
> code, the macro recorder doesn't record setting formats properly (you need
> to use Selection.Find.Font.Bold = True, etc., I think)
>
> I'm happy to help if you have any specific problems but the general one I
> can't see an easy way round I'm afraid.
>
> --
> Enjoy,
> Tony
>
>
> "John Svendsen" <jfs@xxxxxxxxxxxxx> wrote in message
> news:#9umWvO0FHA.2880@xxxxxxxxxxxxxxxxxxxxxxx
> > Hi Tony,
> >
> > First of all, thanks for your interest :-)
> >
> > The idea here is to insert a "\" between any two words which have ANY
> > different formatting. I'll explain: I want to first run a machine
> > translation on paragraphs before revising them for correctness -
however,
> > all machine translators I've seen use the first word's format for the
> whole
> > sentence it translates (sentences are defined by a carriage return or
> ".").
> > To get arround this I first insert a "\" between differently formatted
> words
> > and repalce them with "^p" (carriage returns) so when I run the
translator
> > the formatting of the words is preserved (even though not good, but
better
> > to fix than reformatting all the words again).
> >
> > Again. thanks for your help.
> >
> > Best Regards, JS
> >
> > "Tony Jollans" <No Mail> wrote in message
> > news:O6txn0$zFHA.1168@xxxxxxxxxxxxxxxxxxxxxxx
> > > Hi John,
> > >
> > > Sorry for taking some time to get back - I looked briefly and decided
it
> > > needed some time.
> > >
> > > I have now had a bit of a play with it and it is indeed very slow. I
can
> > > speed it up a little by making some small changes but basically what
it
> is
> > > doing is inherently slow and really needs doing in a different way. I
> > would
> > > guess some code built around Find and Replace would be better but I
need
> > to
> > > run a couple of tests.
> > >
> > > A couple of questions ...
> > >
> > > Do you have words which are both, say, italic and bold?
> > > Do you have any, say, bold text which is not a complete word?
> > >
> > > --
> > > Enjoy,
> > > Tony
> > >
> > >
> > > "John Svendsen" <jfs@xxxxxxxxxxxxx> wrote in message
> > > news:#Kk$rU2zFHA.1264@xxxxxxxxxxxxxxxxxxxxxxx
> > > > Hi Tony,
> > > >
> > > > Thanks so much for your input - truly, you are correct, it is a lot
> > faster
> > > > (I should have thought of using find&Replace.... in the first
place).
> > > >
> > > > Actually, the macro I built is a derivation on another one, which
puts
> > an
> > > > "\" between words that have different formats, colors, etc. (This is
> the
> > > one
> > > > that is REALLY slow). I'm adding it below so maybe you can think of
a
> > way
> > > to
> > > > speed it up.
> > > > Again, thanks so much for your help.
> > > > Rgds, JS
> > > >
> > > > Sub InsertCharBetweenBoldItalicUnderlineWords()
> > > > Selection.WholeStory
> > > > For xxx = Selection.Words.Count To 2 Step -1
> > > > If Selection.Words(xxx).Bold And Not Selection.Words(xxx - 1).Bold
Or
> _
> > > > Not Selection.Words(xxx).Bold And Selection.Words(xxx - 1).Bold Or
_
> > > > Selection.Words(xxx).Italic And Not Selection.Words(xxx - 1).Italic
> Or
> > _
> > > > Not Selection.Words(xxx).Italic And Selection.Words(xxx - 1).Italic
> Or
> > _
> > > > Selection.Words(xxx).Underline And Not Selection.Words(xxx -
> > 1).Underline
> > > > Or _
> > > > Not Selection.Words(xxx).Underline And Selection.Words(xxx -
> > 1).Underline
> > > _
> > > > Then
> > > > Selection.Words(xxx).Select
> > > > Selection.InsertBefore "\"
> > > > Selection.WholeStory
> > > > End If
> > > > Next
> > > > End Sub
> > > >
> > > >
> > > >
> > > > "Tony Jollans" <No Mail> wrote in message
> > > > news:%23YoC791zFHA.464@xxxxxxxxxxxxxxxxxxxxxxx
> > > > > You are potentially asking Word to do a lot of counting through
its
> > > > > collection of words. In a big document it could be slow. There are
> > some
> > > > ways
> > > > > of changing it which might affect performance but the biggest
single
> > > > change
> > > > > you could make in this case is to use Find and Replace.
> > > > >
> > > > > Find *
> > > > > With the cursor in the Find box, click on Format, select Font, and
> > > choose
> > > > > colour Red
> > > > >
> > > > > Replace with (leave empty)
> > > > > Check Use Wildcards
> > > > >
> > > > > Hit Replace All
> > > > >
> > > > > Record yourself doing it if you need code.
> > > > >
> > > > > --
> > > > > Enjoy,
> > > > > Tony
> > > > >
> > > > >
> > > > > "John Svendsen" <jfs@xxxxxxxxxxxxx> wrote in message
> > > > > news:ebiLQ11zFHA.3540@xxxxxxxxxxxxxxxxxxxxxxx
> > > > > > Hi All,
> > > > > >
> > > > > > I need to delete words that are marked in red. So I put together
> > this
> > > > > little
> > > > > > macro, but it is very, very slow!!!
> > > > > >
> > > > > > Sub DeleteWordsInRed()
> > > > > > Selection.WholeStory
> > > > > > For xxx = Selection.Words.Count To 2 Step -1
> > > > > > If Selection.Words(xxx).Font.Color = wdColorRed Then
> > > > > > Selection.Words(xxx).Select
> > > > > > Selection.Delete
> > > > > > Selection.WholeStory
> > > > > > End If
> > > > > > Next
> > > > > > End Sub
> > > > > >
> > > > > >
> > > > > > Can someone give me a clue on how to speed this up?
> > > > > >
> > > > > > Thanks os much, JS
> > > > > >
> > > > > >
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >
> >
> >
>
>
.
- Prev by Date: Re: Change back to the default printer
- Next by Date: Re: .WrapAroundText for tables not working
- Previous by thread: Re: MS Word Macro
- Next by thread: Multiple Page Control and Combo Box
- Index(es):
Relevant Pages
|