ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Programmatically modifying code using VBE in a protected project (https://www.excelbanter.com/excel-programming/420238-programmatically-modifying-code-using-vbe-protected-project.html)

Alex van der Spek[_2_]

Programmatically modifying code using VBE in a protected project
 
I am programmatically changing code lines to allow users to modify a
modelfunction in Excel:

So I use the VBE like:


ThisWorkbook.VBProject.VBComponents("Maincode").Co deModule.ReplaceLine 6,
CodeLine

Does anyone know how to do this and still lock the project for viewing
using a password?

Thanks!
Alex van der Spek

Barb Reinhardt

Programmatically modifying code using VBE in a protected project
 
I'm not aware that you can programmatically lock a project. Think about it,
that could be a very slippery slope if locked projects can be unlocked
programmatically.
--
HTH,
Barb Reinhardt

If this post was helpful to you, please click YES below.



"Alex van der Spek" wrote:

I am programmatically changing code lines to allow users to modify a
modelfunction in Excel:

So I use the VBE like:


ThisWorkbook.VBProject.VBComponents("Maincode").Co deModule.ReplaceLine 6,
CodeLine

Does anyone know how to do this and still lock the project for viewing
using a password?

Thanks!
Alex van der Spek


Jim Thomlinson

Programmatically modifying code using VBE in a protected project
 
Coding against the VBE and password protection do not get along. Your only
option involves using send keys which is hit and miss... Check out this
link...

http://www.cpearson.com/excel/vbe.aspx
Specifically
The VBA Project that you are going to change with these procedures must be
unlocked. There is no programmatic way to unlock a VBA project (other than
using SendKeys). If the project is locked, you must manually unlock.
Otherwise, the procedures will not work.
--
HTH...

Jim Thomlinson


"Alex van der Spek" wrote:

I am programmatically changing code lines to allow users to modify a
modelfunction in Excel:

So I use the VBE like:


ThisWorkbook.VBProject.VBComponents("Maincode").Co deModule.ReplaceLine 6,
CodeLine

Does anyone know how to do this and still lock the project for viewing
using a password?

Thanks!
Alex van der Spek


Barb Reinhardt

Programmatically modifying code using VBE in a protected proje
 
Hi Jim,

I've not used Send Keys and would prefer not to, but why is it's use
problematic?

Thanks,
Barb Reinhardt

"Jim Thomlinson" wrote:

Coding against the VBE and password protection do not get along. Your only
option involves using send keys which is hit and miss... Check out this
link...

http://www.cpearson.com/excel/vbe.aspx
Specifically
The VBA Project that you are going to change with these procedures must be
unlocked. There is no programmatic way to unlock a VBA project (other than
using SendKeys). If the project is locked, you must manually unlock.
Otherwise, the procedures will not work.
--
HTH...

Jim Thomlinson


"Alex van der Spek" wrote:

I am programmatically changing code lines to allow users to modify a
modelfunction in Excel:

So I use the VBE like:


ThisWorkbook.VBProject.VBComponents("Maincode").Co deModule.ReplaceLine 6,
CodeLine

Does anyone know how to do this and still lock the project for viewing
using a password?

Thanks!
Alex van der Spek


Alex van der Spek[_2_]

Programmatically modifying code using VBE in a protected project
 
I had not thought of using SendKeys myself. That should work, but it is
cumbersome indeed.

How about splitting the code in two parts:

1. One locked project stored in an Add-in. This project contains the main
code including the bit that manipulates the VBE.
2. One unlocked file, the user front end. This project contains the one
line of code that should be modified at the user's wish (updating a model
function). The modification, however is done by the locked project which
contains the VBE manipulation code.

Would that work?

Thanks!
Alex van der Spek



All times are GMT +1. The time now is 05:17 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com