none
VBProject protection via code (Excel) RRS feed

  • Question

  • Is there any way that you can import a module and then make it protected ?

    I use   With WorkObject.VBComponents
                   .Import WorkMacro
               End With                       after exporting the macro in the first place thus

    ActiveWorkbook.VBProject.VBComponents("Module2") _
                    .Export WorkMacro

    It does it this way because the user runs the macro from within a Workbook that contains two modules and it creates an output file via one module that has a VBA module included (second module) so the user can then share or open the output file and navigate around it etc.

    I can't just protect the module "at source" because it needs to be unprotected to do the export/import

    But I do want the module to be protected to prevent tinkering or users looking at sensitive code

    Hope this makes sense

    Thursday, October 20, 2011 2:39 AM

Answers

  • It can be done with SendKeys, albeit very unreliably which kind of defeats the objective. There's another approach involving APIs to process the various controls in the same UI that's used normally. I developed something along those lines to batch process unlocking, modifying, relocking multiple projects. It's a lot of code though and complicated, too much to post here. It's a lot more reliable than SendKeys but I not 100%, for my purposes it was to save the work of doing it all manually. There are no other easy reliable ways!

    Maybe a different approach, can the code be rewritten to accept updatable external inputs. Or instead of code in the workbook supply an additional addin, and revised addins as required.

    Peter Thornton

    • Marked as answer by jeff Whale Thursday, October 20, 2011 7:12 PM
    Thursday, October 20, 2011 11:51 AM
    Moderator

All replies

  • It can be done with SendKeys, albeit very unreliably which kind of defeats the objective. There's another approach involving APIs to process the various controls in the same UI that's used normally. I developed something along those lines to batch process unlocking, modifying, relocking multiple projects. It's a lot of code though and complicated, too much to post here. It's a lot more reliable than SendKeys but I not 100%, for my purposes it was to save the work of doing it all manually. There are no other easy reliable ways!

    Maybe a different approach, can the code be rewritten to accept updatable external inputs. Or instead of code in the workbook supply an additional addin, and revised addins as required.

    Peter Thornton

    • Marked as answer by jeff Whale Thursday, October 20, 2011 7:12 PM
    Thursday, October 20, 2011 11:51 AM
    Moderator
  • Thanks for the response Peter

    As I feared, I may need to look at alternative methods as per your last sentence - worth a try though

    Thursday, October 20, 2011 7:11 PM