+ Reply to Thread
Results 1 to 10 of 10

VB Code does not work in Protected Mode

  1. #1
    Registered User
    Join Date
    09-06-2019
    Location
    Brentwood, TN
    MS-Off Ver
    2016
    Posts
    20

    VB Code does not work in Protected Mode

    I have a VB Code that allows me to select multiple items from a list and have them separated by a comma. The code does not function in Protected Mode. Does anyone know how to fix this?

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: VB Code does not work in Protected Mode

    If a file comes up in Protected Mode it should give you an option to allow macros to run. The whole point of Protected Mode is to protect you from malicious content from untrusted sources. If you are feeling particularly invulnerable you can reconfigure Excel not to use Protected Mode.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Registered User
    Join Date
    09-06-2019
    Location
    Brentwood, TN
    MS-Off Ver
    2016
    Posts
    20

    Re: VB Code does not work in Protected Mode

    Thank you Jazzer. I would like to run the code in Protected mode because I have adjacent cells that contain formulas that I don't want to accidentally modify.

  4. #4
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: VB Code does not work in Protected Mode

    I think you may confusing two things.

    Protected Mode is a special mode in Microsoft Office that limits what you can do in a file of dubious origin.

    Do you mean that you have protected a worksheet so that formulas can't be changed? This does not prevent code from running. I think we need a little more detail. What do you mean "The code does not function"?

    • Does the code run?
    • Does it run but do nothing?
    • Does it produce error messages? If so, what do the messages say?
    • Does it produce unexpected/wrong results? If so, how do the results differ from what you expect?
    • Does it hang?

    It might help to attach your file, and say what macro you are referring to.

  5. #5
    Registered User
    Join Date
    09-06-2019
    Location
    Brentwood, TN
    MS-Off Ver
    2016
    Posts
    20

    Re: VB Code does not work in Protected Mode

    Apologies for not being more clear. The VBA Code which i have below does not operate when I have the worksheet it is assigned to "Protected". I have cells locked that I don't want a user to modify but I want the VBA Code to operate. See the attached photo. The VBA Code allows me to select multiple items and have them displayed in the same cell, separated by commas. The Cells directly to the right, have formulas that calculate the values of the items selected, which I want to protect so no one deletes them BUT I want the VBA Code to function and allow me to select multiple items at the same time, but I am unable to do so when the sheet is Protected. I hope this makes sense.Attachment 642178

    VBA Code:
    Please Login or Register  to view this content.
    Last edited by 6StringJazzer; 09-20-2019 at 08:12 AM.

  6. #6
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: VB Code does not work in Protected Mode

    Moderator's note: Please take the time to review our rules. There aren't many, and they are all important. Rule #2 requires code tags. I have added them for you this time because you are a new member. --6StringJazzer

  7. #7
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: VB Code does not work in Protected Mode

    Thanks for the additional information. However, you did not answer my key question: What happens when you try to run the code? How is that different than what you expect to happen?

    Which cells are protected?

    There was a problem with your image attachment. Next time, try to Preview your post before adding the image tag, then preview again to confirm before sending the post.

    Also, you can attach your actual Excel file, which might be a good idea in this case. The paper clip icon does not work for attachments. To attach a file, under the text box where you type your reply click the Go Advanced button. On the next screen scroll down and click on Manage Attachments, which will show a pop-up window to Select and Upload a file. Then close the window.

  8. #8
    Registered User
    Join Date
    09-06-2019
    Location
    Brentwood, TN
    MS-Off Ver
    2016
    Posts
    20

    Re: VB Code does not work in Protected Mode

    I made an example worksheet which i have attached. When the worksheet is protected, i am only able to select one item from the list...I need to select multiple items from the list when the worksheet is protected.
    Attached Files Attached Files

  9. #9
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: VB Code does not work in Protected Mode

    Now we're getting somewhere.

    The following line of code

    Please Login or Register  to view this content.
    is raising an error
    nathanledbetter=Capture.JPG

    You did not realize this because of

    Please Login or Register  to view this content.
    I am not sure why you are trapping errors here. You should not use this unless you know what error you are expecting to happen.

    The way to manage this is for the code to unprotect the sheet, do its work, the reprotect it.

    I have also reorganized your code a bit to make it more readable. Using ":" to putting If/Else parts on the same line gets confusing. I also strongly discourage GoTo statements and have made a small change that eliminates it.

    Also I strongly recommend to everyone that they declare variables. Doing so prevents a lot of bugs and runtime errors.

    Please Login or Register  to view this content.

  10. #10
    Registered User
    Join Date
    09-06-2019
    Location
    Brentwood, TN
    MS-Off Ver
    2016
    Posts
    20

    Re: VB Code does not work in Protected Mode

    Thank you, 6StringJazzer!!!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] VBA code works in debug mode but misses steps running in normal mode
    By supereeg in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-18-2016, 05:42 AM
  2. VBA AutoFilter does not Work in run mode, only in debug mode
    By aganove in forum Excel Programming / VBA / Macros
    Replies: 19
    Last Post: 11-19-2015, 04:32 PM
  3. [SOLVED] Code skips on Run Mode but runs fine on F8 (Debug Mode)
    By RaquelAR in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 11-25-2013, 01:05 PM
  4. Checkbox doesn't work in protected mode
    By djkeyclub in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-15-2013, 06:30 PM
  5. [SOLVED] Found GREAT print VBA, but wont work on protected workbook can anyone help me with code?
    By NicksDad in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-30-2012, 02:25 PM
  6. Replies: 0
    Last Post: 06-28-2012, 01:08 AM
  7. [SOLVED] How to make this code work even if the cells are locked and sheet is protected
    By nenadmail in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-22-2012, 01:14 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1