Important Guidelines When Using Recorded Macros
Recorded macros replay a sequence of steps exactly as they were recorded. This can lead to unexpected errors. For example, close the worksheet in the notebook Exponential Data Set 1.jnb so that only the notebook window is displayed. Now select Toolbox, Macros, Exponential Fit. The following error message is displayed
Click Ok to see what failed in the macro. The statement where the error occurred is highlighted.
The problem is that there is no CurrentPageItem (highlight CurrentPageItem and press F1 to see its definition). The page isn’t open so it isn’t current. We recorded the macro by right clicking on the graph page so every time you use the macro it expects the graph page to be open.
What if your data isn’t in columns 1, 2 and 3? You won’t get an error but this obviously will not work since the macro was recorded to fit data in these columns.
What if you have data in a second section in the notebook? If you try this, the macro halts with the error “Object var is Nothing” and displays the offending statement
When you recorded the macro, the data worksheet name was “Data 1”. In the second section of the notebook the data worksheet name is “Data 2”. So the macro can’t find the correct worksheet and fails. If you add a dialog then you certainly could include a dropdown that includes all worksheets in the notebook. Then the user could select the desired worksheet.