Results 1 to 3 of 3

Thread: Excel sheet protection and VBA code

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    May 2004
    Location
    Right here
    Posts
    275

    Excel sheet protection and VBA code

    Does anyone know how to get Excel to allow VBA code to write to a password protected worksheet?

    I am using a work-around solution at the moment whereby the VBA unprotects the relevant worksheet, writes data to it, then re-protects it.

    There must be a better way than this though. Obviously I don't want my users to delete the formulas etc in the worksheet but I want my code to be able to write data to the worksheet without having to unprotect/re-protect it all the time!

    Thanks
    -Rob
    http://www.sudsolutions.com

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Excel sheet protection and VBA code

    I think the only way is to do as you are. You could possibly add a new sheet as the "Display" sheet and have it linked to your
    actual sheet. I think the protected "Dsiplay" sheet will still update as you change the "hidden" sheet.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3
    I don't do your homework! opus's Avatar
    Join Date
    Jun 2000
    Location
    Good Old Europe
    Posts
    3,863

    Re: Excel sheet protection and VBA code

    I used the method unprotect/protect in a excel-file, it works fine.
    For each entry the code starts off with unprotecting and at the end it protects the file again. I had no problem with that.

    Why don't you leave the cells that unprotected where user entries are allowed?
    If your formulas are not in those cells, nothing can happen!
    You're welcome to rate this post!
    If your problem is solved, please use the Mark thread as resolved button


    Wait, I'm too old to hurry!

Posting Permissions

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



Click Here to Expand Forum to Full Width