• Word has insufficient memory (Word 2002 XP)

    Home » Forums » AskWoody support » Productivity software by function » Visual Basic for Applications » Word has insufficient memory (Word 2002 XP)

    Author
    Topic
    #437860

    Hi

    On some very large documents, eg 250 pages when running some in-house code on the Word warning message appears ” Word has insufficient memory. You will not be able to undo this action once its completed. Do you want to continue?”

    Is there anyway to capture this msg before it appears and then clear the Undo buffer?

    In the below code the message box is appearing on the line & is kinda in a loop. Is there a better way to perform this function without the “memory” message?

    .Execute Replace:=wdReplaceAll

    Public Sub CleanUPIDDFieldcodes()

    Dim myStoryRange As Range
    Dim strSearch As String

    On Error Resume Next

    strSearch = “Error! No document variable supplied.”


    ‘ first search the main document using the Selection

    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
    .Text = strSearch
    .Replacement.Text = “”
    .Forward = True
    .Wrap = wdFindContinue
    .Format = False
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    .Execute Replace:=wdReplaceAll
    End With


    ‘ now search all other stories using Ranges
    ‘ this includes the headers & footers

    For Each myStoryRange In ActiveDocument.StoryRanges
    If myStoryRange.StoryType wdMainTextStory Then
    With myStoryRange.Find
    .Text = strSearch
    .Replacement.Text = “”
    .Wrap = wdFindContinue
    .Execute Replace:=wdReplaceAll
    End With
    Do While Not (myStoryRange.NextStoryRange Is Nothing)
    Set myStoryRange = myStoryRange.NextStoryRange
    With myStoryRange.Find
    .Text = strSearch
    .Replacement.Text = “”
    .Wrap = wdFindContinue
    .Execute Replace:=wdReplaceAll
    End With
    Loop
    End If
    Next myStoryRange

    On Error GoTo 0

    End Sub

    many thanks diana

    Viewing 2 reply threads
    Author
    Replies
    • #1042261

      There is an UndoClear method, and you could run it before doing the replace. However, if the problem persists because your one replace operation makes that many changes, I don’t see how you can avoid the error. Or is there a way to temporarily disable Undo altogether? Hmmm…

    • #1042277

      does application.DisplayAlerts=wdAlertsNone help?

    • #1042279

      I find this works for me:

      ''' Word's "formatting" bug forces us to save our document every so often.
      ''' How often? Each 500 paragraphs seems to be the trick.
      ''' Hooray for virtual (ram) disks!
      Dim lngParagraphs As Long
      lngParagraphs = Int(ActiveDocument.Paragraphs.Count / 500)
      Dim lngOldParagraphs As Long
      If lngOldParagraphs  lngParagraphs Then
          lngOldParagraphs = lngParagraphs
          doc.Save
      Else
      End If
      
    Viewing 2 reply threads
    Reply To: Word has insufficient memory (Word 2002 XP)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: