How to unprotect and Unhide sheets when running a macro

  • Hello experts


    I need your expertise to find the fault in the code and solution to correct this. I have this workbook where the data is pasted in one sheet ”Original” from column A to J whose cells are not locked and not hidden. The rest of the sheet is protected with a password and the cells are hidden and locked. The macro button is in column K. Other than this sheet there are several other sheets which are protected and hidden. When I run the code, the code should unprotect and unhide all the protected and hidden sheets in the workbook. When the macro ends, I want the code to again protect and hide all the other sheets which were already hidden. The columns A:J in Original sheet must stay unlocked and unhidden at all times.

  • Hello Roy. I am facing some issues. As you suggested, I have removed unprotection from the sheets.

    When I run the first Macro Button it unhides the sheets but at the end of the code I need to hide the sheets again. In the code of the first macro, I have added a line below Sub() to unhide the sheets and at the end of the macro I have added another line to hide the sheets before End Sub. The error highlights the "Hidesheets." and displays - compile error Expected variable or procedure, not module.



  • If I remove the Hidesheets line from the code, then the code runs correctly and generates an xml file. But the sheets are not hidden. What line of code should I add to the code to hide the sheets.?

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!