Consulting

Results 1 to 3 of 3

Thread: Solved: Code runs on other open workbooks

  1. #1
    VBAX Tutor
    Joined
    Jul 2010
    Posts
    225
    Location

    Solved: Code runs on other open workbooks

    Hi. I have some protect worksheet codes that if I have another workbook open will protect the sheets on that workbook as well as the one this code lies within. Is there something I should do differnt to ensure the code I write only runs in the workbook I have the code? This happens with other code I use as well?



    [VBA]Sub ProtectAll()
    Application.ScreenUpdating = False
    Dim Sh As Worksheet
    Dim myPassword As String
    myPassword = password
    For Each Sh In activeWorkbook.Worksheets
    Sh.Protect Password:=myPassword

    Next Sh
    Sheets("sheets 1").Visible = False
    Application.ScreenUpdating = True
    End Sub[/VBA]

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    Sub ProtectAll()
    Dim Sh As Worksheet
    Dim myPassword As String

    Application.ScreenUpdating = False

    myPassword = password

    For Each Sh In ThisWorkbook.Worksheets
    Sh.Protect Password:=myPassword

    Next Sh
    ThisWorkbook.Sheets("sheets 1").Visible = False

    Application.ScreenUpdating = True
    End Sub
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Tutor
    Joined
    Jul 2010
    Posts
    225
    Location
    So simple but what a difference it makes......thanks sooo much.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •