View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Doug Glancy Doug Glancy is offline
external usenet poster
 
Posts: 770
Default Error 28 out of stack space

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

"JIM" wrote in message
...
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.