Consulting

Results 1 to 5 of 5

Thread: Excel VB "Unprotect" workbook statement

  1. #1

    Excel VB "Unprotect" workbook statement

    I have a current macro that works...opens files, updates, saves, then close. See below.
    Sub TestUpdate()
    Workbooks.Open Filename: = V:\user folder\filename.xls, updatelink:=3
    ActiveWorkbook.Save
    ActiveWindow.Close
    End Sub
    We are having issues with the Protected view prompt, enable editing. This stops our macros, and we run through about 25 files with this current macro. How do I add the VB "Unprotect" statement that will turn this off on every file when it is opened, before the update begins?

    Thank you for your help !!
    Last edited by Aussiebear; 04-19-2023 at 04:26 AM. Reason: Added code tags

  2. #2
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    Try this
    Sub UnProtectingWorkbooks()
    Const Passwurd As String = "???"
    
    Workbooks.Open Filename: = "V:\user folder\filename.xls", updatelink:=0
    With ActiveWorkbook
       .UnProtect Passwurd 'If PAssword needed
       .updatelinks
       .Save
       .Protect Passwurd 'If PAssword needed
       .Close
    End With
    End Sub
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  3. #3
    I keep getting a run-time error 424, object required.

  4. #4
    Also, this is not password protected, but files open in protected view, enable editing.

  5. #5
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,711
    Location
    TRY this to see if it works for you (Excel 2016)

    Excel Options

    Trust Center

    Trust Center Settings

    Protected View

    and uncheck the three boxes

    Capture.JPG
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

Posting Permissions

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