Delete userform/module using VB

  • Thread starter Thread starter Rohit Thomas
  • Start date Start date
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
 
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
 
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
 
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)
 
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
 
Back
Top