
Creating a custom Undo solution?
I have a macro that calculates plan forecast for a project. In order to do
that i right the calculated plan forecast % into the percent complete
column. Before I do that however, I write the current value from percent
complete column to text16 column. Then I have an undo key that takes the
values from the text16 column and writes them back to the percent complete
column. It works fine as long as they only run the plan macro once. Code
excerpts below.
Hope it helps,
Brad
Sub Planned_Percent_Complete()
On Error GoTo ErrorHandler
'Get the reporting date.
Dim rptdate As Date
rptdate = InputBox("This will overwrite the current values in the %
Complete field and in Text16. Save copy before running. " _
& Chr(13) & "Report date for planned forecast calculation?" &
Chr(13) & "(mm/dd/yy)", "Plan Forecast")
'Loop through each task in the project
For Each ATask In ActiveProject.tasks
PlPctComp = 0
'skip blank rows
If Not ATask Is Nothing Then
ATask.Text16 = "" 'set text 16 to null
'skip summary tasks
...PlPctComp calculation code....
'write actual % complete to Text15 field
ATask.Text16 = ATask.PercentComplete & "%"
'write planned % complete to percent complete field
ATask.PercentComplete = PlPctComp
End If
End If
Next ATask
.....error handler etc.....
End Sub
Sub Undo_Planned_Forecast()
On Error GoTo ErrorHandler
For Each ATask In ActiveProject.tasks
'skip blank rows
If Not ATask Is Nothing Then
'skip summary tasks
If ATask.Summary = No Then
If IsNull(Text16) = False Then
ATask.PercentComplete = ATask.Text16
End If
End If
End If
Next ATask
MsgBox "Plan Forecast has been undone.", vbOKOnly, "Undo Plan Forecast"
Exit Sub ' Exit to avoid handler.
ErrorHandler: ' Error-handling routine.
MsgBox "Undo Planned Forecast failed please contact management",
vbOKOnly
End Sub
Quote:
> Project doesn't have an undo/redo list for more than the last action -
even
> then somethings can not be undone.
> Sometimes you can store previous values so that they can be restored
later,
> but this will require careful consideration if you want to have multiple
> levels of undo.
> Obviously it is a difficult problem or project would offer this function
> (and it still doesn't!)
> For a simple example of a macro which restores previous values look at the
> one titled "Remove Contraints" at
> http://masamiki.com/project
> --
> Please try to keep replies in this group. I do check e-mail, but only
> infrequently.
> For Macros and other things check http://masamiki.com/project
> -Jack Dahlgren, Project MVP
> +++++++++++++++++++
> > Hi,
> > I am trying to create an undo feature for my macros. Each macro now has
> > several dozens of actions that I would like to see undone when I click
> > either the standard undo button or a custom undo button. I have had
> limited
> > success with the undo x and undoAction where I manually apply a value to
a
> > variable and then use it in an object.undo var statement.
> > Is there a better way of doing an undo function?
> > Is there a way to access the names of actions directly from the redo
> > dropdown box?
> > Can I access the standard undo/redo list and program from them or should
I
> > create a custom approach? If so, how do I do this?
> > Thank you for your help,
> > Paul