Error 28 out of stack space

J

JIM

I'm doing the simplest task - to fill a cell with a ctrl+a key with the
following code:

Sub PrintName()
'
' PrintName Macro
' Print Waterbury
' Keyboard Shortcut: Ctrl+a
'
ActiveCell.FormulaR1C1 = ""
Range("A1:D1").Select
With Selection
.HorizontalAlignment = xlLeft
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = True
End With
Application.CommandBars("Stop Recording").Visible = False
Application.CommandBars("Task Pane").Visible = False
ActiveCell.FormulaR1C1 = "Waterbury"
Range("C2").Select
Application.Run "PERSONAL.XLS!PrintName" 'it stops here
ActiveWorkbook.SaveAs Filename:= _
"C:\Documents and Settings\Monty\My Documents\Book1.xls",
FileFormat:= _
xlNormal, Password:="", WriteResPassword:="",
ReadOnlyRecommended:=False _
, CreateBackup:=False
ActiveWindow.Close
Workbooks.Add
End Sub
It stops at line -Application.Run "Personal.XLS!PrintName" and highlights it
yellow. I get a run-time error 28: Out of stack space. It seems to be in a
continuous loop until it runs out of memory.
Any hints appreciated.
 
D

Doug Glancy

Jim,

You are calling PrintName from inside of PrintName, which then calls
PrintName, which then ...

As you say, this is an endless loop. The error that you are seeing "out of
stack space" is another way to say that your code is stuck in an endless
loop.

The solution is to not call the routine from inside the routine.

hth,

Doug
 

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