Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Annoying crash

Status
Not open for further replies.

DrkMAtter

MIS
Jun 6, 2003
5
CA
Hello,
When I run the following code on my Word Document:

Public Sub setTextColumns(ByRef LeDoc As Document)

Dim c As Long
Dim x As Range

For c = 2 To LeDoc.InlineShapes.Count - 1
Set x = LeDoc.Range( _
LeDoc.InlineShapes(c).Range.End + 1, _
LeDoc.InlineShapes(c + 1).Range.Start)

LeDoc.Range(Start:=LeDoc.InlineShapes(c).Range.End+1, _
End:=LeDoc.InlineShapes(c).Range.End). _
InsertBreak Type:=wdSectionBreakContinuous

LeDoc.Range(Start:=LeDoc.InlineShapes(c + 1).Range.Start, _
End:=LeDoc.InlineShapes(c + 1).Range.Start). _
InsertBreak Type:=wdSectionBreakContinuous

x.PageSetup.TextColumns.SetCount 3


Next c


I get, about 30 loops through, message saying "Not enough memory. When this action will finish, it will be impossible to undo. Continue?", to which I answer yes.
The problem is, at this point, my code stops running, and Word shuts down without further warning. I tried to check out exactly how many lines of code after the message prompt this happenned, but by adding Message Boxes to find out, the warning stopped appearing and Word didn'T crash.

Now, I know my problem is kind of fixed, but I'm jsut really confused as to WHY this happens. Does anyone have an idea?
 
Not an expert but don't you need a "Set x=nothing" in there somewhere to release used memory.

Maybe before the next x statement.

 
No, setting x = will re-use the memory previously assigned to x.

But I think you will have a problem with
Code:
 LeDoc.InlineShapes(c + 1).Range
when c is pointing to the last item.

Perhaps if you shortened the loop:
Code:
   For c = 2 To LeDoc.InlineShapes.Count - 2
 
Indeed, I did have a problem with my loop count, thanks.

Well, now it seems adding message boxes in there won't stop it from crashing anymore. Are there any ways to monitor free memory from within VBA? And which statement am I using tht could hug up that much memory?

Just to make sure, I did try to free x with Set x = Nothing , but it did not help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top