Reputation: 69
I have a macro I made that exports a pivot chart every hour: but I just got this run-time error saying out of stack space this is my code:
Sub saveFile()
With Application.ThisWorkbook
Dim objChart As ChartObject
Dim myChart As Chart
ActiveWorkbook.RefreshAll
DoEvents
Set objChart = Sheets("Chart").ChartObjects(1)
Set myChart = objChart.Chart
today = Sheets("Date Range").Range("D1").Value
myFileName = "IRF - Daily Receiving " & today & ".jpg"
On Error Resume Next
myChart.Export Filename:="\\syncreon.local\data\Redford\Common\Daily Reports\IRF\Receiving\" & myFileName, Filtername:="JPG"
On Error GoTo 0
saveFile
Application.OnTime Now + TimeValue("01:00:00"), "saveFile"
End With
End Sub
Anything I can do with this?
Upvotes: 0
Views: 281
Reputation: 882078
You are actually calling saveFile
from within saveFile
, leading to infinite recursion that will naturally run out of stack space eventually.
I'm not sure why you're doing that since you also seem to be setting up an event to call the function one hour hence.
My advice is to get rid of the explicit call to saveFile
and simply rely on the Application.OnTime
to schedule it at a later time.
Upvotes: 1