View Single Post
 
Old 03-06-2018, 08:51 AM
lars-daniel lars-daniel is offline Windows 7 64bit Office 2010 32bit
Novice
 
Join Date: Mar 2018
Posts: 6
lars-daniel is on a distinguished road
Default VBA is crashing after about 350 pages

Hi there,

I'm having a huge mailmerge document with 6,000 pages and many tables and columns. Each cell with "-1" inside it should get a grey background. Since I was not able to do this using IF function, I'm trying it with VBA (see below).

Description of the workflow: I'm running a very simple code to get through all the columns of all tables in my word document, make its background to "grey" and remove the content, if its numeric content is "-1".

On a 250 page document (mailmerge page 1-250), anything works fine. At 350 pages or more, the whole thing crashes at
Code:
c.Range.Text = ""
My Office 2010 is 32-bit, but it's far from memory limited. I also tried this code on Office 2016, but the code never completed... seems like VBA integration got worse there.

Anyone with an idea on how to make it better or fix it? "Conditionally Shade Table Cells" trick doesn't work here, since the margins of some cells can't be set to zero.

Code:
Sub grey()
  Application.ScreenUpdating = False
  Dim tbl As Table
  Dim c As Word.Cell
  For Each tbl In ActiveDocument.Tables
    For Each c In tbl.Range.Cells
      If Val(c.Range.Text) = -1 Then
        c.Shading.BackgroundPatternColor = wdColorGray10
        c.Range.Text = ""
      End If
    Next
    Set c = Nothing
  Next
  Application.ScreenUpdating = True
End Sub
Best,
Lars-Daniel
Reply With Quote