Consulting

Results 1 to 4 of 4

Thread: Use VBA code in a locked worksheet

  1. #1
    VBAX Newbie
    Joined
    Jun 2020
    Posts
    2
    Location

    Use VBA code in a locked worksheet

    I am using Excel 365 64-bit, and am a novice with VBA. I've created an Excel file with charts in which the minimal X-axis values vary widely based on input values. I have copied and pasted VBA code that auto adjusts the vertical minimal values, but when I protect the worksheet where the graphs are located, the VBA function no longer works. Is it possible to include VBA code in a locked worksheet? Thanks!

  2. #2
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,711
    Location
    Without seeing the macro (at least) it's hard to tell

    Attach a small workbook with the chart and the macro to this thread (how to in my sig)
    ---------------------------------------------------------------------------------------------------------------------

    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

  3. #3
    VBAX Newbie
    Joined
    Jun 2020
    Posts
    2
    Location

    Use VBA code in a locked worksheet

    Quote Originally Posted by Paul_Hossler View Post
    Without seeing the macro (at least) it's hard to tell

    Attach a small workbook with the chart and the macro to this thread (how to in my sig)
    Attached is the unlocked file. The charts are in the "Inputs and Summary" worksheet.

    Thanks!

  4. #4
    You can unprotect a sheet, run your code then re-apply protection.

    Option Explicit
    
    Sub x()
    ''/// change the password here
        Const PW As String = "secret"
        On Error GoTo exit_proc
        Sheet1.Unprotect PW
        ''/// your code here
    exit_proc:
        Sheet1.Protect PW
    End Sub
    The other option is to use Protect with UserInterFaceOnly

    See here for an explanation and free example workbook

    http://excel-it.com/excel_userinterfaceonly.html
    Hope that helps.
    Get the free Excel based Toolbar or click here for free examples & Excel Consultancy

    RoyUK

Tags for this Thread

Posting Permissions

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