Stop the message 'Word has insufficient memory' ...

Robie
5StarLounger
Posts: 656
Joined: 18 Feb 2010, 14:26

Stop the message 'Word has insufficient memory' ...

Post by Robie »

Hi

I have a requirement to 'import' document based on x template into a y template. The import (VBA code) works fine where copying is involved etc. It also has to reset the Heading styles to match the new template, change the case, etc. BTW: I have switched off track changes.

For this I use the code below. Only problem is that some of these documents are absolutely huge (1500 pages +) and I keep getting this message:
undomsg.png
The code is:

Code: Select all

Function SetCaps(style2Check As Variant)
'
'   SetCaps Function
'
    Selection.SetRange Start:=ActiveDocument.Sections(4).Range.Start, _
                       End:=ActiveDocument.Sections(4).Range.End
    Do
        With Selection.Find
            .ClearFormatting
            .Text = ""
            .Forward = True
            .Format = True
            .Wrap = wdFindStop
            .Style = style2Check
            If .Execute Then
                Selection.Range.Style = style2Check
                Selection.Range.Case = wdLowerCase
                Selection.Range.Case = wdTitleSentence
            Else
                Exit Function
            End If
        End With
    Loop
End Function
Is there a way to switch off the undo/redo functionality temporarily or is there a better way of achieving what I have in my code? Also, my code takes absolutely ages to achieve this.

Thanks.
You do not have the required permissions to view the files attached to this post.

User avatar
HansV
Administrator
Posts: 78493
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Stop the message 'Word has insufficient memory' ...

Post by HansV »

You could put the line

ActiveDocument.UndoClear

within the loop. This line clears the undo stack.
Best wishes,
Hans

User avatar
HansV
Administrator
Posts: 78493
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Stop the message 'Word has insufficient memory' ...

Post by HansV »

By the way, do you really need both these lines?

Selection.Range.Case = wdLowerCase
Selection.Range.Case = wdTitleSentence

It may help if you add a line

Application.ScreenUpdating = False

near the beginning of your code, and

Application.ScreenUpdating = True

near the end.
Best wishes,
Hans