0

Is it possible to protect VBA code from different file vba code?

I want to write a macro which for all files in given directory set project properties - protection - lock project for viewing:

manual example .

Regards, Piotrek

//EDIT

I've tried:

sub setVBAPassword(ws as Worksheet)
dim oVBP as VBProject
set oVBP = ws.VBProject
    oVBP.VBE.CommandBars("Menu Bar").Controls("Tools") _
        .Controls("VBAProject Properties...").Execute
With Application
    .SendKeys "^{TAB}"
    .SendKeys "{ }"
    .SendKeys "{TAB}" & "test"
    .SendKeys "{TAB}" & "test"
    .SendKeys "{TAB}"
    .SendKeys "{ENTER}"
End With
end sub

problem is, that it is setting password to vb project that runs a macro. question is how can I switch to some other project, or how can I open VBE in other ws context?

1 Answers1

0

In Visual Studio, go to Tools, then go to "****Properties" (*** = your project name). There is a protection tab. Should be easy to find from there.

Doug Coats
  • 6,255
  • 9
  • 27
  • 49
  • Doug, I need to do it for many files, question is if it is possible with vba code, not manualy – Piotr Wojtaszewski May 16 '16 at 13:00
  • Im not entirely sure how to do that off the top of my head. However I am sure you can incorporate a loop, you just have to dig around and find out what Object property you would need to use to do this. That being said, here's a good reference. http://stackoverflow.com/questions/16363621/protecting-code-in-an-excel-workbook/28968867#28968867 – Doug Coats May 16 '16 at 13:08