View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Greg Wilson Greg Wilson is offline
external usenet poster
 
Posts: 747
Default Protect macro and close VBE programatically

The following line should close the VBE:
Application.VBE.MainWindow.Visible = False

As for protecting the project, I think you're stuck with using Sendkeys.
Check out Sendkeys in Help. I don't have the Help file loaded on this
machine, so the appended code example is from memory only. It appears to work
but probably could be improved.

I have commented out the last Tab and Enter ("{TAB}~") which will close the
dialog and not let you see what happens. I did the same for the line that
closes the VBE. Uncomment these in your code.

Regards,
Greg

Const pwd As String = "monkey"

Sub Test()
With Application
.SendKeys "%Te+{TAB}{Right}", True
.SendKeys "%v", True
.SendKeys "%p" & pwd, True
.SendKeys "%c" & pwd, True
'.SendKeys "{TAB}~"
'DoEvents
'.VBE.MainWindow.Visible = False
End With
End Sub


"biosci" wrote:


I have a macro that writes another macro programatically. Does anyone
know how to protect the VBA code and then close VBE progrmatically?


--
biosci
------------------------------------------------------------------------
biosci's Profile: http://www.excelforum.com/member.php...o&userid=32827
View this thread: http://www.excelforum.com/showthread...hreadid=531147