简体   繁体   中英

protect VBA code for viewing using VBA code

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM