I am having problems with my Outlook freezing when I run macros
containing WORD VBA in them. I posted this to the Outlook forum, but
the MVP there suggested I try here as it is the Word VBA code that
seems to be causing this.

Since outlook is set up to use word as my email editor I want to be
able to take advantage of macros stored in my Normal.dot template to
perform some simple text searches & replacements.

After running a macro in an email message window (new messages or
replies) , the send button along with every other button/tool on that
row of Outlook toolbars (i.e. the Accounts drop-box, the attachment
icon, address book button, options, etc.) becomes disabled. I kind of
need the SEND button! I click, but nothing happens. The buttons are
all dead. They no longer change color when hovered over, or animate,
etc. I've tested it on 3 machines at work as well as my computer at
home and can replicate it 100% of the time.

I have isolated the problem to one Selection.Find statement, but
haven't done any exhaustive testing to be sure something else can't
trigger it as well. Here's the example:

Sub RemovePhone()
'
' RemovePhone Macro
' Macro recorded 2/14/2006 by JG
'
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "^#^#^#-^#^#^#-^#^#^#^#"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
End Sub

The last statement in the sub -- the Select.Find -- is the only one
that, if commented out or removed, stops the freezing behavior.

Any help would be greatly appreciated as this is driving me crazy and
slowing me down having to manually replace text in each message.

Thanks!
Jim
(Using Office XP Pro SP3 with windows XP Pro.)

Re: Word VBA causing my outlook to freeze up. by Cindy

Cindy
Mon Feb 20 04:14:29 CST 2006

Hi Jim

Hmmm, and I'd have sent you back to the Outlook group :-)

If you use Find from the user interface, the problem doesn't occur? Just
when running macro code?

I wonder if Find using the RANGE object would behave differently. See
what this sample code does:

Dim rng as Word.Range
Set rng = Selection.Range
With rng.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = "^#^#^#-^#^#^#-^#^#^#^#"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.Execute Replace:=wdReplaceAll
End With

> I am having problems with my Outlook freezing when I run macros
> containing WORD VBA in them. I posted this to the Outlook forum, but
> the MVP there suggested I try here as it is the Word VBA code that
> seems to be causing this.
>
> Since outlook is set up to use word as my email editor I want to be
> able to take advantage of macros stored in my Normal.dot template to
> perform some simple text searches & replacements.
>
> After running a macro in an email message window (new messages or
> replies) , the send button along with every other button/tool on that
> row of Outlook toolbars (i.e. the Accounts drop-box, the attachment
> icon, address book button, options, etc.) becomes disabled. I kind of
> need the SEND button! I click, but nothing happens. The buttons are
> all dead. They no longer change color when hovered over, or animate,
> etc. I've tested it on 3 machines at work as well as my computer at
> home and can replicate it 100% of the time.
>
> I have isolated the problem to one Selection.Find statement, but
> haven't done any exhaustive testing to be sure something else can't
> trigger it as well. Here's the example:
>
> Sub RemovePhone()
> '
> ' RemovePhone Macro
> ' Macro recorded 2/14/2006 by JG
> '
> Selection.Find.ClearFormatting
> Selection.Find.Replacement.ClearFormatting
> With Selection.Find
> .Text = "^#^#^#-^#^#^#-^#^#^#^#"
> .Replacement.Text = ""
> .Forward = True
> .Wrap = wdFindContinue
> .Format = False
> .MatchCase = False
> .MatchWholeWord = False
> .MatchWildcards = False
> .MatchSoundsLike = False
> .MatchAllWordForms = False
> End With
> Selection.Find.Execute Replace:=wdReplaceAll
> End Sub
>
> The last statement in the sub -- the Select.Find -- is the only one
> that, if commented out or removed, stops the freezing behavior.
>
> Any help would be greatly appreciated as this is driving me crazy and
> slowing me down having to manually replace text in each message.
>
> Thanks!
> Jim
>

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question
or reply in the newsgroup and not by e-mail :-)


Re: Word VBA causing my outlook to freeze up. by DontEvenBother

DontEvenBother
Tue Feb 21 23:11:12 CST 2006

Thank you, thank you, thank you Cindy!

What I don't know about VBA could fill a black hole, but the range
object proved to be the workaround I was looking for.

FWIW, to answer your first question, using Find from the user interface
does Not produce the error. It was only when running Macro code.

I thank you again for your help. I have been struggling with this for
some time and it is quite a relief to finally get past it.

Jim


Re: Word VBA causing my outlook to freeze up. by Cindy

Cindy
Thu Feb 23 10:15:37 CST 2006

> the range
> object proved to be the workaround I was looking for.
>
thank you for confirming it worked :-) good luck with your
project!

Cindy Meister


Re: Word VBA causing my outlook to freeze up. by Alejandro

Alejandro
Wed Mar 08 13:13:26 CST 2006

Hi Cyndy,

My name is Alex and I have the same problem Jim had, but the solution you
posted didn't work for me. In this macro I'm trying to validate text in the
Word document.
The following is the code that doesn't work, and, like with Jim's
application, the problem is in the Find statement. I already applied to this
code the solution you provided.

Dim rng As Word.Range
For Each myStoryRange In ActiveDocument.StoryRanges
myStoryRange.Select
For iStrNum = 0 To 19
Set rng = Selection.Range
With rng.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = aSearchStr(iStrNum)
.Forward = True
.Wrap = wdFindContinue
.MatchCase = True
.MatchWildcards = True
.Replacement.Text = "\1^s"
.Execute Replace:=wdReplaceAll
End With
Next
Next myStoryRange

It works fine when it validates the MainText Story, but it is sooooooo slow
when it is processing footer and header stories.

Any help would be highly appreciated!

--
Thanks!

Alex


"Cindy M -WordMVP-" wrote:

> > the range
> > object proved to be the workaround I was looking for.
> >
> thank you for confirming it worked :-) good luck with your
> project!
>
> Cindy Meister
>
>