Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.misc
|
|||
|
|||
Ignore macro run time error
Iget the following error message
"Run Time error 1004 Unable to get the legendentries property of the legend class" This occurs when users enter invalid parameters for a query that fetches data for a pivot table, among other stuff. Can the macro ignore the error so users are not tempted to debug the macro code? The macro can then complete and the user can input valid parameters. |
#2
Posted to microsoft.public.excel.misc
|
|||
|
|||
Ignore macro run time error
Hi Phil
You need to use the bulit-in error handler. Below is an example of how it can be done. Sub Test() 'User enter parameters On Error GoTo ErrHandler ' Code that throws error On Error GoTo 0 ' Stop error handler 'Rest of your code Exit Sub ' Stop before ErrHandler ErrHandler: msg = MsgBox("Invalid parameters, macro abort.", vbCritical, "Best regards, Per Jessen") End Sub Regards, Per "phil" skrev i meddelelsen ... Iget the following error message "Run Time error 1004 Unable to get the legendentries property of the legend class" This occurs when users enter invalid parameters for a query that fetches data for a pivot table, among other stuff. Can the macro ignore the error so users are not tempted to debug the macro code? The macro can then complete and the user can input valid parameters. |
#3
Posted to microsoft.public.excel.misc
|
|||
|
|||
Ignore macro run time error
Per,
Thanks for you answer but this is where the error happens in the code "ActiveChart.Legend.LegendEntries(5).LegendKey.Sel ect" There is no legend because there is no data to fetch and it will happen at each legend entry x5. (I had to write this part of the macro to format the legend to the preffered layout from default after the pivot refreshed.) Which part of the code is going in above or below the place where the error occurs to stop the error message and allow the macro to complete without doing the formatting? "Per Jessen" wrote: Hi Phil You need to use the bulit-in error handler. Below is an example of how it can be done. Sub Test() 'User enter parameters On Error GoTo ErrHandler ' Code that throws error On Error GoTo 0 ' Stop error handler 'Rest of your code Exit Sub ' Stop before ErrHandler ErrHandler: msg = MsgBox("Invalid parameters, macro abort.", vbCritical, "Best regards, Per Jessen") End Sub Regards, Per |
#4
Posted to microsoft.public.excel.misc
|
|||
|
|||
Ignore macro run time error
Phil,
Given the new information, this is how to handle it. On Error Resume Next ' Ignore lines that throws error (after this statement) Activechart.Legend.LegendEntries.... ' Code to set other legends On error Goto 0 ' Disable the Error Handling ' Continue with other code Regards, Per "phil" skrev i meddelelsen ... Per, Thanks for you answer but this is where the error happens in the code "ActiveChart.Legend.LegendEntries(5).LegendKey.Sel ect" There is no legend because there is no data to fetch and it will happen at each legend entry x5. (I had to write this part of the macro to format the legend to the preffered layout from default after the pivot refreshed.) Which part of the code is going in above or below the place where the error occurs to stop the error message and allow the macro to complete without doing the formatting? "Per Jessen" wrote: Hi Phil You need to use the bulit-in error handler. Below is an example of how it can be done. Sub Test() 'User enter parameters On Error GoTo ErrHandler ' Code that throws error On Error GoTo 0 ' Stop error handler 'Rest of your code Exit Sub ' Stop before ErrHandler ErrHandler: msg = MsgBox("Invalid parameters, macro abort.", vbCritical, "Best regards, Per Jessen") End Sub Regards, Per |
#5
Posted to microsoft.public.excel.misc
|
|||
|
|||
Ignore macro run time error
Excellent, thank you Per
"Per Jessen" wrote: Phil, Given the new information, this is how to handle it. On Error Resume Next ' Ignore lines that throws error (after this statement) Activechart.Legend.LegendEntries.... ' Code to set other legends On error Goto 0 ' Disable the Error Handling ' Continue with other code Regards, Per "phil" skrev i meddelelsen ... Per, Thanks for you answer but this is where the error happens in the code "ActiveChart.Legend.LegendEntries(5).LegendKey.Sel ect" There is no legend because there is no data to fetch and it will happen at each legend entry x5. (I had to write this part of the macro to format the legend to the preffered layout from default after the pivot refreshed.) Which part of the code is going in above or below the place where the error occurs to stop the error message and allow the macro to complete without doing the formatting? "Per Jessen" wrote: Hi Phil You need to use the bulit-in error handler. Below is an example of how it can be done. Sub Test() 'User enter parameters On Error GoTo ErrHandler ' Code that throws error On Error GoTo 0 ' Stop error handler 'Rest of your code Exit Sub ' Stop before ErrHandler ErrHandler: msg = MsgBox("Invalid parameters, macro abort.", vbCritical, "Best regards, Per Jessen") End Sub Regards, Per |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
MACRO Run Time Error 1004 | Excel Discussion (Misc queries) | |||
Macro Run-time error | Excel Discussion (Misc queries) | |||
Macro Issue - Run time error 1004 | Excel Discussion (Misc queries) | |||
Macro time out error | Excel Worksheet Functions | |||
Visual Basic macro run time error(13) type mismatch | Excel Discussion (Misc queries) |