I had to solve the same problem to satisfy my graduate school's requirements for my Ph.D. dissertation (which specified that section headings should not appear in the table of contents for appendices, though they had to appear for all headings BEFORE the appendices).
The following command should work for you:
Code: Select all
\addtocontents{toc}{\protect\setcounter{tocdepth}{0}}
You can change the zero to another number if you want to change the numbering depth, of course.
NOTE: If you include this command as part of the re-definition of \appendix and then \include the first chapter immediately after the \appendix command, as I did, you will find that the command takes effect AFTER the first appendix. This is built into the LaTeX kernel. The way around it is to ALSO put the line above as the first line of the \include'd file. All subsequent \include's will honor your new tocdepth.
If you want ALL sections of a certain level to appear (or not), of course, you can set the counter in the preamble instead.
Welcome to the forum!