+ Reply to Thread
Results 1 to 15 of 15

VBA Macro not working when workbook is protected

  1. #1
    Registered User
    Join Date
    04-22-2008
    Posts
    42

    VBA Macro not working when workbook is protected

    I wish I could have been more specific with my Title. This is what I am encountering. I used the McGimpsey code for generating a unique sequential number every time a workbook opens. I tailored the code to fit my needs and stuck it into my invoice sheet. For the longest time I was unable to make it work until I moved the code from a template to a standard workbook. Then I was able to make it work as long as the sheet was unprotected. I realized that to get the code to work I had to then unprotect the cells that the code was writing to. Now that I've done that I am getting errors in the code that weren't there before, rendering the macro useless. The code I am using is:

    Please Login or Register  to view this content.
    I am getting errors on the ".NumberFormat = "dd-mmm-yy"" line and ".NumberFormat = "@""

    I am out of ideas at this point. Can someone give me a hand please? BTW, I'm running Excel 2007.

    Justin
    Last edited by JustinMAS; 04-23-2008 at 04:28 PM.

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678
    Please edit your post to add code tags and to have a title descriptive of your problem.

  3. #3
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678
    You need to either unlock the cells to be manipulated, or unprotect the sheet in VBA before before doing so.

    If you protect the sheet in VBA with the UserInterfaceOnly option set to True, then you can manipulate the cells without unprotecting the sheet. If you elect to go this way, see the remarks in Help for the Protect method regarding UserInterfaceOnly.

  4. #4
    Registered User
    Join Date
    04-22-2008
    Posts
    42
    I have unlocked the cells. I am still getting the error whenever I open the worksheet.

  5. #5
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678
    Post the workbook?

  6. #6
    Registered User
    Join Date
    04-22-2008
    Posts
    42
    Here you go!
    Attached Files Attached Files

  7. #7
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678
    Cells Z10 and Z11 are merged, and Z10 was unlocked but not Z11. Unlock both and it works fine.

    Merging cells is a bad idea.

  8. #8
    Registered User
    Join Date
    04-22-2008
    Posts
    42
    I am really new to Excel "programming". Up until now the deepest I have gotten would be to use formulas in a sheet. Is there a better way to achieve what I was attempting to do?

  9. #9
    Registered User
    Join Date
    04-22-2008
    Posts
    42
    I just went into the worksheet, I un-merged the dispatch number block, set the protection on all of those cells to unprotected, re-merged the cells, saved and reopened the document and I still have the same error. I also tried unmerging and using on cell and I am getting the same error "Run-Time Error '1004': Unable to set the number format property of the range class"
    Last edited by JustinMAS; 04-23-2008 at 05:34 PM.

  10. #10
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678
    Post it again?

  11. #11
    Registered User
    Join Date
    04-22-2008
    Posts
    42
    As soon as I get back to work tomorrow I'll post it again. Thanks for all of your help. I truly appreciate it.

  12. #12
    Registered User
    Join Date
    04-22-2008
    Posts
    42
    Here it is again with the changes I made. BTW if you want to unprotect the sheet, it isn't password protected.
    Attached Files Attached Files

  13. #13
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678
    When you protect the sheet, under Allow all users of this worksheet to:, check Format cells.

  14. #14
    Registered User
    Join Date
    04-22-2008
    Posts
    42
    I did what you suggested and lo and behold, IT WORKED!!! Thanks so much for all of your help. Again, it is truly appreciated.

  15. #15
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678
    You're welcome, Justin.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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