dcsimg
Results 1 to 4 of 4

Thread: Vb code

  1. #1

    Thread Starter
    Registered User
    Join Date
    Jun 2018
    Posts
    1

    Vb code

    CAN ANYONE PLEASE EXPLAIN FUNCTIONALITY OF THE BELOW CODE

    Private Sub Workbook_Open()
    Dim ws As Worksheet
    Dim pwd As String

    pwd = "PGHV" ' Put your password here
    For Each ws In Worksheets
    ws.Protect Password:=pwd, UserInterfaceOnly:=True
    Next ws

    With Worksheets("Jan 2018")
    .EnableOutlining = True
    .Protect UserInterfaceOnly:=True
    End With

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    39,850

    Re: Vb code

    Welcome to VBForums

    Thread moved from the 'VB.Net' forum to the 'Office Development/VBA' forum.

  3. #3
    PowerPoster
    Join Date
    Dec 2004
    Posts
    23,543

    Re: Vb code

    when the workbook opens, the code should lock all worksheets with the supplied password
    it then attempts to lock the jan 2018 worksheet, but as that worksheet is already locked with a password it may well fail
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  4. #4
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    1,235

    Re: Vb code

    Nevermind, that this supposed "Functionality" is the same as killing a dead horse.
    The User just has to set his "Macro-Security" to high, and the code doesn't get executed --> Result: Sheet is not protected
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    I say you're crazy not to!
    --------------------------------------------------------------------------------------------------
    For health reasons i try to avoid reading unformatted Code

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width


×
We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.