ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   remove module via code (https://www.excelbanter.com/excel-programming/429399-remove-module-via-code.html)

mikeallen77

remove module via code
 
I have 2 vba modules that are both within a protected project. I wish
to remove one module via code from the other module. I have this in
"module1":

ThisWorkbook.VBProject.vbcomponents.Remove
ThisWorkbook.VBProject.vbcomponents("module2")

It works fine IF I have the project unprotected, but the problem
arises when the project is protected. I get:

Run-time error '50289': Can't perform operation since the project is
protected.

Someone suggested once to go to Tools--Macros--Security--Trusted
Publishers--Trust access to Visual Basic project (click box). I have
this done, but still does not work when protected. I must have
project protected because others will be using this file and I do not
want them to have access to the sensitive code in 'module2'. The
users will need 'module2' initially to run program, then they will be
converting the program into an output-only file w/ no 'module2'.

Thanks

Jim Thomlinson

remove module via code
 
From Chip Pearson's web site...

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.

http://www.cpearson.com/excel/vbe.aspx

Note that using send keys is a VERY hit and miss method of executing code.
--
HTH...

Jim Thomlinson


"mikeallen77" wrote:

I have 2 vba modules that are both within a protected project. I wish
to remove one module via code from the other module. I have this in
"module1":

ThisWorkbook.VBProject.vbcomponents.Remove
ThisWorkbook.VBProject.vbcomponents("module2")

It works fine IF I have the project unprotected, but the problem
arises when the project is protected. I get:

Run-time error '50289': Can't perform operation since the project is
protected.

Someone suggested once to go to Tools--Macros--Security--Trusted
Publishers--Trust access to Visual Basic project (click box). I have
this done, but still does not work when protected. I must have
project protected because others will be using this file and I do not
want them to have access to the sensitive code in 'module2'. The
users will need 'module2' initially to run program, then they will be
converting the program into an output-only file w/ no 'module2'.

Thanks


Dave Peterson

remove module via code
 
If you want to remove that module via code, then each user will have to have
that trusted publisher setting checked. And the project will have to be
unprotected.

If you don't want to unprotect the project, maybe you can move the code to one
workbook/addin and the data to another.

Or maybe you can create a workbook on the fly that has no code in it and just
paste your formulas/values into that workbook's worksheets?

If there's lots of formatting that you have to do and you don't want to do in
via code, then create a template file with all the stuff you like (no code!) and
use that to create the workbook that will receive the data.

mikeallen77 wrote:

I have 2 vba modules that are both within a protected project. I wish
to remove one module via code from the other module. I have this in
"module1":

ThisWorkbook.VBProject.vbcomponents.Remove
ThisWorkbook.VBProject.vbcomponents("module2")

It works fine IF I have the project unprotected, but the problem
arises when the project is protected. I get:

Run-time error '50289': Can't perform operation since the project is
protected.

Someone suggested once to go to Tools--Macros--Security--Trusted
Publishers--Trust access to Visual Basic project (click box). I have
this done, but still does not work when protected. I must have
project protected because others will be using this file and I do not
want them to have access to the sensitive code in 'module2'. The
users will need 'module2' initially to run program, then they will be
converting the program into an output-only file w/ no 'module2'.

Thanks


--

Dave Peterson

Dave Peterson

remove module via code
 
If you want to remove that module via code, then each user will have to have
that trusted publisher setting checked. And the project will have to be
unprotected.

If you don't want to unprotect the project, maybe you can move the code to one
workbook/addin and the data to another.

Or maybe you can create a workbook on the fly that has no code in it and just
paste your formulas/values into that workbook's worksheets?

If there's lots of formatting that you have to do and you don't want to do in
via code, then create a template file with all the stuff you like (no code!) and
use that to create the workbook that will receive the data.

mikeallen77 wrote:

I have 2 vba modules that are both within a protected project. I wish
to remove one module via code from the other module. I have this in
"module1":

ThisWorkbook.VBProject.vbcomponents.Remove
ThisWorkbook.VBProject.vbcomponents("module2")

It works fine IF I have the project unprotected, but the problem
arises when the project is protected. I get:

Run-time error '50289': Can't perform operation since the project is
protected.

Someone suggested once to go to Tools--Macros--Security--Trusted
Publishers--Trust access to Visual Basic project (click box). I have
this done, but still does not work when protected. I must have
project protected because others will be using this file and I do not
want them to have access to the sensitive code in 'module2'. The
users will need 'module2' initially to run program, then they will be
converting the program into an output-only file w/ no 'module2'.

Thanks


--

Dave Peterson


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

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