Macro causes Word 2007 to crash

K

KumbiaKid

Hi,

I've recorded the following macros which are intended to format all of the
grid lines in a table to 1-1/2 point solid lines. Both macros run just fine
in Word 2000, but crash Word on the indicated line when I run them in Word
2007. If I comment out that one line, the macros run, but don't do the whole
job. I recorded the macro originally in Word 2007 and when I found that
version crashed every time, I recorded it again in Word 2000 with the same
result when I run it on Word 2007. Note that the crash is Word (MS Office has
encourtered a problem and needs to close . . .), not just the macro. Any
ideas why?

Both versions of Word are running on machines with Win XP Pro SP2 with all
updates (except SP3) and both versions of Word are fully patched. Both
machines have plenty of RAM and disk space.

Thanks for any help.
KumbiaKid

The Word 2007 version:

Selection.Tables(1).Select
With Selection.Borders(wdBorderBottom)
.LineStyle = Options.DefaultBorderLineStyle
.LineWidth = Options.DefaultBorderLineWidth
.Color = Options.DefaultBorderColor
End With
With Selection.Borders(wdBorderTop)
.LineStyle = Options.DefaultBorderLineStyle
.LineWidth = Options.DefaultBorderLineWidth
.Color = Options.DefaultBorderColor
End With
With Selection.Borders(wdBorderLeft)
.LineStyle = Options.DefaultBorderLineStyle
.LineWidth = Options.DefaultBorderLineWidth
.Color = Options.DefaultBorderColor
End With
With Selection.Borders(wdBorderRight)
.LineStyle = Options.DefaultBorderLineStyle
.LineWidth = Options.DefaultBorderLineWidth
.Color = Options.DefaultBorderColor
End With
With Selection.Borders(wdBorderHorizontal)
.LineStyle = Options.DefaultBorderLineStyle
' The following line causes Word 2007 to crash and restart:
.LineWidth = Options.DefaultBorderLineWidth
.Color = Options.DefaultBorderColor
End With
With Selection.Borders(wdBorderVertical)
.LineStyle = Options.DefaultBorderLineStyle
.LineWidth = Options.DefaultBorderLineWidth
.Color = Options.DefaultBorderColor
End With


The Word 2000 version:
Sub TestTableGrid()
'
' TestTableGrid Macro
' Macro recorded 26/Jan/2009 using Word 2000
'
Selection.Tables(1).Select
With Selection.Tables(1)
With .Borders(wdBorderLeft)
.LineStyle = wdLineStyleSingle
.LineWidth = wdLineWidth150pt
.Color = wdColorAutomatic
End With
With .Borders(wdBorderRight)
.LineStyle = wdLineStyleSingle
.LineWidth = wdLineWidth150pt
.Color = wdColorAutomatic
End With
With .Borders(wdBorderTop)
.LineStyle = wdLineStyleSingle
.LineWidth = wdLineWidth150pt
.Color = wdColorAutomatic
End With
With .Borders(wdBorderBottom)
.LineStyle = wdLineStyleSingle
.LineWidth = wdLineWidth150pt
.Color = wdColorAutomatic
End With
With .Borders(wdBorderHorizontal)
.LineStyle = wdLineStyleSingle
' The following line causes Word 2007 to crash and restart:
.LineWidth = wdLineWidth150pt
.Color = wdColorAutomatic
End With
With .Borders(wdBorderVertical)
.LineStyle = wdLineStyleSingle
.LineWidth = wdLineWidth150pt
.Color = wdColorAutomatic
End With
.Borders(wdBorderDiagonalDown).LineStyle = wdLineStyleNone
.Borders(wdBorderDiagonalUp).LineStyle = wdLineStyleNone
.Borders.Shadow = False
End With
End Sub
 
D

Doug Robbins - Word MVP

Use:

With Selection.Tables(1)
.Borders(wdBorderHorizontal).LineWidth = wdLineWidth150pt
.Borders(wdBorderLeft).LineWidth = wdLineWidth150pt
.Borders(wdBorderRight).LineWidth = wdLineWidth150pt
.Borders(wdBorderTop).LineWidth = wdLineWidth150pt
End With


--
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
 
K

KumbiaKid

Thanks Doug, for your speedy reply. Sadly, that didn't alter the result. The
exact macro, in full, that I tried:

Sub TestTable()
'
' TestTable Macro
'
'
Selection.Tables(1).Select
With Selection.Tables(1)
.Borders(wdBorderHorizontal).LineWidth = wdLineWidth150pt
.Borders(wdBorderLeft).LineWidth = wdLineWidth150pt
.Borders(wdBorderRight).LineWidth = wdLineWidth150pt
.Borders(wdBorderTop).LineWidth = wdLineWidth150pt
End With
End Sub

Still, Word 2007 crashes. I moved the "Horizontal" line to the end and
stepped through the macro:
Sub TestTable()
'
' TestTable Macro
'
'
Selection.Tables(1).Select
With Selection.Tables(1)
.Borders(wdBorderLeft).LineWidth = wdLineWidth150pt
.Borders(wdBorderRight).LineWidth = wdLineWidth150pt
.Borders(wdBorderTop).LineWidth = wdLineWidth150pt
.Borders(wdBorderHorizontal).LineWidth = wdLineWidth150pt
End With
End Sub

The "Left", "Right", and "Top" lines execute OK, but when I step into the
"Horzontal" line, Word dies.

Seems very strange to me.?
KumbiaKid
 
D

Doug Robbins - Word MVP

It does not cause any problems for me. Possibly there is some other
corruption in that table to which you are trying to apply these settings.

--
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
 
K

KumbiaKid

Thanks Doug. Do I understand you to say that the macro works on your system?
I have tried this on an empty table in a new document. I re-booted the
system, started Word, created a table with "Table/Insert Table" from the menu
and immediately applied the macro -- same result. Perhaps there's something
corrupted in our Word 2007 installation. I have tried the repair procedure
which doesn't find anything, so I suppose I'll have to try a re-install or
just forget this unless something else turns out to be messed up. Any other
thoughts? Thanks again.
KumbiaKid
 
K

KumbiaKid

P.S. to my previous post. It seems odd to me that all of the other statements
in these macros are OK and that just that one statement crashes Word without
even generating a trappable error in vba. Does that seem bizzare to anyone
else?
KumbiaKid
 
D

Doug Robbins - Word MVP

Yes, it works on my system with causing an error or crash.

--
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
 
K

KumbiaKid

Well. I've done a bit more exploring and have found a work-around. Doug, your
original thought that there might be something corrupt with the table turns
out to have some validity. My macros failed on new empty tables until I
followed the "What to do when Word crashes" advice from
http://www.gmayor.com/what_to_do_when_word_crashes.htm.
After deleting all the temp files, the macros ran fine on new test tables,
but still crashed on my "original" table which was pasted into Word from 4
selected columns in an Access query (should I have mentioned that originally?
if so, sorry). The work around is that I select the table, do a convert table
to text, then immediately a convert text to table, then run the macro -- all
is well! Ah, the mysteries of Office . . .
 
K

KumbiaKid

One final post on this thread. I want to thank Doug Robbins especially for
his help and also Greg Mayor for his informative and helpful web site. You
guys who invest so much time helping us who know so much less is very much
appreciated.

Cheers,
KumbiaKid
 
D

Doug Robbins - Word MVP

Thanks for the recognition. It is much appreciated.

--
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
 
G

Graham Mayor

Even though my name is not Greg ;)

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
K

KumbiaKid

Oops. Sorry Graham. Short-term memory crash, I guess. Your web site is
nonetheless very helpful. Thanks again for making it available.

Cheers,
KumbiaKid
 
G

Graham Mayor

Don't worry, I have been called much worse ;)

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top