+ Reply to Thread
Results 1 to 12 of 12

Add code to a macro for the purpose of unlocking a project for viewing

  1. #1
    Registered User
    Join Date
    04-02-2013
    Location
    california, usa
    MS-Off Ver
    Excel 2010
    Posts
    33

    Add code to a macro for the purpose of unlocking a project for viewing

    I want to protect my project 'Lock My Project from viewing.' This issue is that I need to delete all the macros before sending it for reviews. I have a macro I run that deletes all the macros in my workbook. However, because the project is 'Lock My Project from viewing' the macro will not run. Is there any code I can add to this macro that would first 'unlock the project' and the continue with the delete?

  2. #2
    Forum Expert
    Join Date
    01-12-2007
    Location
    New Jersey
    Posts
    2,127

    Re: Add code to a macro for the purpose of unlocking a project for viewing

    I'm not sure if that is possible. Just an idea: why not try to develop a macro that copies and then pastes each sheet into a new, macro-less workbook, then send that new workbook out?

  3. #3
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Add code to a macro for the purpose of unlocking a project for viewing

    Hi, ekr,

    have you tried saving as *.xlsx which should delete all macro code from a workbook?

    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  4. #4
    Registered User
    Join Date
    04-02-2013
    Location
    california, usa
    MS-Off Ver
    Excel 2010
    Posts
    33

    Re: Add code to a macro for the purpose of unlocking a project for viewing

    That will work - I will have to create a macro to save as this file type instead of deleting macros. Thanks.

  5. #5
    Registered User
    Join Date
    04-02-2013
    Location
    california, usa
    MS-Off Ver
    Excel 2010
    Posts
    33

    Re: Add code to a macro for the purpose of unlocking a project for viewing

    If I create a macro to save as an .xlsx, then the user will get a popup that states .... do you want to save this as a macro-free workbook. I do not want them to have a choice. The workbook cannot get distributed with macros

  6. #6
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Add code to a macro for the purpose of unlocking a project for viewing

    Hi, ekr,

    use

    Please Login or Register  to view this content.
    Ciao,
    Holger

  7. #7
    Registered User
    Join Date
    04-02-2013
    Location
    california, usa
    MS-Off Ver
    Excel 2010
    Posts
    33

    Re: Add code to a macro for the purpose of unlocking a project for viewing

    Almost there ... I put the following code between the two lines you provided. I must have an error in my code because I am trying to save as excel 2010 .xlsx and it saves it as 97 - hence another error message for the user.
    Please Login or Register  to view this content.

  8. #8
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Add code to a macro for the purpose of unlocking a project for viewing

    Hi, ekr,

    Fileformat for xlsx is either 51 or xlOpenXMLWorkbook but not x51Normal.

    Ciao,
    Holger

  9. #9
    Registered User
    Join Date
    04-02-2013
    Location
    california, usa
    MS-Off Ver
    Excel 2010
    Posts
    33

    Re: Add code to a macro for the purpose of unlocking a project for viewing

    OK, I think it is the code I'm using to save
    Please Login or Register  to view this content.

  10. #10
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Add code to a macro for the purpose of unlocking a project for viewing

    Hi, ekr,

    add the extension to the filename. I slightly altered your code for name and path:
    Please Login or Register  to view this content.
    Ciao,
    Holger

  11. #11
    Registered User
    Join Date
    04-02-2013
    Location
    california, usa
    MS-Off Ver
    Excel 2010
    Posts
    33

    Re: Add code to a macro for the purpose of unlocking a project for viewing

    I now get code out of range. All I want to do is have the macro save the doc as a .xlsx file and not prompt the user so that the user will not have a choice - otherwise they will choose to keep the macros. I have tried the following
    Please Login or Register  to view this content.
    I just cannot seem to get it to work.

  12. #12
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Add code to a macro for the purpose of unlocking a project for viewing

    Hi, ekr,

    Please Login or Register  to view this content.
    The string from GetSaveAsFilename contains path, name and extension, so there is no need to add that once again.

    Ciao,
    Holger

+ 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