+ Reply to Thread
Results 1 to 9 of 9

VBA Project Password Stripped when saving as .xlsx

  1. #1
    Registered User
    Join Date
    08-04-2009
    Location
    Maryland, US
    MS-Off Ver
    Excel 2003
    Posts
    5

    VBA Project Password Stripped when saving as .xlsx

    I have an excel file that is distributed within my organization. That file contains certain worksheets that the end-users do not need to see or make changes to, so in the VBA project, I change those files to "VeryHidden". Then I protect the workbook's VBA code by going to Tools->VBAProject- Project Properties-> Protection tab and adding a password. This worked great as it allowed all the other sheets to function as intended, but didn't allow the users to access the sheets that were hidden.

    However, we recently upgraded to Excel 2007, and the password protection is stripped whenever the file is saved with the extension .xlsx. I can save it as a "macro-enabled" file with the extension .xlsm, but all that needs to be done to remove the password is to save it with the .xlsx extension again. Is there something that can be done in Excel 2007 to protect VBA code, or am I doing something completely wrong?

    This is my first post here, so please let me know if I've done something wrong!
    Last edited by DRoberts; 08-11-2009 at 11:40 AM. Reason: solved

  2. #2
    Valued Forum Contributor Richard Schollar's Avatar
    Join Date
    05-23-2006
    Location
    Hampshire UK
    MS-Off Ver
    Excel 2002
    Posts
    1,264

    Re: VBA Project Password Stripped when saving as .xlsx

    Hi

    If the workbook is saved as an .xlsx file it would (or should!) also remove the VBA code (ie all VBA modules would be removed from the file). Is this not what you are observing?

    Richard
    Richard Schollar
    Microsoft MVP - Excel

  3. #3
    Registered User
    Join Date
    08-04-2009
    Location
    Maryland, US
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: VBA Project Password Stripped when saving as .xlsx

    Yes, this is what I am observing, unfortunately. There's no actual "code" in the VBA project, I was just using the password to prevent the end-users from changing the visibility of the sheet from "Very Hidden" (which removes it from the main Excel's hide/unhide dialogue). It seems that I cannot do that anymore because saving it as an .xlsx file removes the password, and thus enables the end-user to change the visibility back to "Visible".

  4. #4
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: VBA Project Password Stripped when saving as .xlsx

    There is nothing you can do about that as far as I know, unfortunately. (it's not particularly secure anyway)
    Remember what the dormouse said
    Feed your head

  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

    Re: VBA Project Password Stripped when saving as .xlsx

    You could use code in the Workbook_BeforeSave event to prevent the user from doing a SaveAs.

    Then you would also need to force users to enable macros, a topic covered extensively in the forum.
    Entia non sunt multiplicanda sine necessitate

  6. #6
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: VBA Project Password Stripped when saving as .xlsx

    Just protecting the VBA project will not prevent unhiding sheets. A few simple lines of code from another workbook could unhide the sheets
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  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

    Re: VBA Project Password Stripped when saving as .xlsx

    Protecting the workbook would add a level of difficulty.

  8. #8
    Registered User
    Join Date
    08-04-2009
    Location
    Maryland, US
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: VBA Project Password Stripped when saving as .xlsx

    I realize that this method was not secure to any great extent, it was just meant to add a hurdle beyond that provided by the "Very Hidden" property itself. I will look into the VBA events possibility, but the end-users need to be able to SaveAs with a different file name, just not change the extension itself. In any event, I've received the main answer I was looking for, so I'll be marking this as solved. Thank you all for your assistance.

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

    Re: VBA Project Password Stripped when saving as .xlsx

    If you intercept the SaveAsUI, you can cancel that and replace it with a GetSaveAsFilename dialog and prevent the user from changing the extension.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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