need modified VBA

  • hi below is the VBA to lock all excel files in a folder, it is locking all sheet in a workbook, but i want to lock only first two sheet of each workbook. I am a mechanical engineer i have no idea, can some one plz modify it


  • Change

    Code
    1. For Each ws In wb.Sheets
    2. ws.Protect "Welcome"
    3. Next

    To

    Code
    1. ws.Sheets(1).Protect "Welcome"
    2. ws.Sheets(2).Protect "Welcome"

    We now have a reputation system in place. If my reply helped please "Like" the reply by clicking the "Like" icon at bottom right of my reply.

  • Sorry, my bad.


    Should be wb not ws

    Code
    1. wb.Sheets(1).Protect "Welcome"
    2. wb.Sheets(2).Protect "Welcome"

    We now have a reputation system in place. If my reply helped please "Like" the reply by clicking the "Like" icon at bottom right of my reply.