Delete userform/module using VB

R

Rohit Thomas

Hello All,

Is it possible to delete a userform or module from an
Excel project programmatically? If it is possible, can you
provide some sample code or point me to a website where I
can find some?

Thanks,
Rohit Thomas
 
R

Rohit Thomas

Chip,

Thanks for the response. I took a look at your website and
have one question....If my project is password protected,
is there code that I can run to unprotect it before
deleting the userform or module. It would need to be
protected after the useform or module is deleted.

Thanks,
Rohit
 
R

Randall Arnold

Rohit, you can use the following:

ThisWorkbook.Unprotect Password:="passwd"

Substitute your known password for "passwd".

Protect works the same way. Same goes for the ActiveWorksheet. Execute
them in the Workbook_Open and Workbook_BeforeClose event subs.

Randall Arnold
 
C

Chip Pearson

Randall,
ThisWorkbook.Unprotect Password:="passwd"


That doesn't unprotect the VBProject -- the VBA code behind the
workbook. Unfortunately, there is no way to programmatically
protect or unprotect a VBProject. You can sometimes get SendKeys
to do it, but I don't recommend it.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com (e-mail address removed)
 
R

Randall Arnold

Ok, you're right-- I was just thinking of the Workbook.

Personally, I don't think it's a good thing to be able to programmatically
unprotect the code... one has to simultaneously deal with self-reference,
quantum mechanics and time travel. Who needs THAT???

; )

Randall Arnold
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top