Click to See Complete Forum and Search --> : EXCEL VB and VBE - hummm...
TheFIDDLER
Mar 31st, 2004, 07:31 PM
Can this be done...
Is it possible to have code within a VBA module, that once activated via a button on a worksheet, would open the VBE Editor, and given a password found within its own code, unlock its own module for viewing.
Just trying to save me a bit of time each time I open my files for editing. Working on a global - programmer password that unlocks all my sheets, gives me back my toolbars, and hopefully, opens up my VBE for me.
RobDog888
Apr 2nd, 2004, 12:08 AM
Yes you can access the VBA Projects through code, but I havent
found anything yet on passing the passwords. Here is the first
step in allowing access to the project through code.
To turn on trusted access to Visual Basic Projects:
1.) On the Tools menu, point to Macro, and then click Security.
2.) On the Trusted Sources tab, select the Trust access to Visual
3.) Basic Project check box.
After that I wrote this code and saved it in a document (not the
Normal.dot template) to prompt you to turn project protection off,
but the property is read only and can not be set programmatically. :cry:
So, I ended up writting more to open the VBA editor and attempt
to open the project. So this is where I am at and its time to go to
sleep. Have to go to client site tomorrow to do a db migration.
Option Explicit
Private Sub Document_Open()
Call AltF11
End Sub
Private Function AltF11()
MsgBox "Opening the VBA editor", vbOKOnly + vbInformation
Application.ShowVisualBasicEditor = True
If MsgBox("Turn project protection off?", vbYesNo + vbQuestion) = vbYes Then
'VBE.VBProjects.Item("Project").Protection = 0 'Read Only Property.
End If
MsgBox "Cant programmatically turn off protection." _
& vbNewLine & "I will try to open the project for you!", vbOKOnly + vbInformation
VBE.VBProjects.Item("project").VBE.CodePanes.Item(1).Show
'VBE.VBProjects.Item("project").VBE.CodePanes.Item(1).Window.Close 'Closes the project
End FunctionDont forget to turn trusted access to Visual
Basic Projects back off when you are done. Security threat.
RobDog888
Apr 3rd, 2004, 02:23 PM
Any luck yet, TheFIDDLER?
TheFIDDLER
Apr 3rd, 2004, 02:46 PM
ACtually - got sidetracked with a few loose ends I have to fix to meet a deadline. Will look at it tonight. THanks.
RobDog888
Apr 3rd, 2004, 03:46 PM
Working on the weekend? Are you a contractor or just trying to get ahead?
I kind of feel that there will not be any simple solution to it, or
any at all, in this area. Looks like M$ locked it down for security
reasons.
:cry:
ps. any relation to The Riddler from Batman? ;)
TheFIDDLER
Apr 3rd, 2004, 06:26 PM
Working weekend - yup!
This is actually my second job. I am the manager of a retail store during the day. Computer programmer with my own software company by night.
Never met the Riddler - doubt were related - but it is a small world. Name came from me trying to learn how to play the fiddle.
RobDog888
Apr 3rd, 2004, 08:13 PM
What is your company name?
Was it hard to start your own software company? I had thought
about it a couple of years ago until the economy fell apart. So for
now, I am staying with the computer consulting company I am
currently at for a while more.
:(
TheFIDDLER
Apr 3rd, 2004, 10:22 PM
I called it Estimator One Software. Specializing in home estimating software for the retail building supply industry.
Actually came as an off-shoot where other stores in my buying group saw some of my work and asked how they could get a copy of the software. My program is now in use from coast to coast.
So I spend a bit of time each day on these bulletin boards trying to learn new things and to get better at what I do.
I have a new release due out at the end of April, so that's why I've been posting all these tidbits.
Going to back to our post topic -
Here is how to get it working:
First if using Excel 2002 - Security - Check trusted sources. Otherwise this will lock out the vbproject.
ALso, you need a reference to Microsoft Visual Basic for Applications Extensionability.
Haven't got the password part yet, but it is fairly easy to open the VB editor using code. You can manipulate the object model without too much complications. I will play around with it so that I get it opening with my preferences and screen layout.
Also works with 97, 2000 and 2002.
sub showVBE()
Dim oVBE As VBIDE.VBE
Set oVBE = Application.VBE
oVBE.MainWindow.Visible = True
End sub
RobDog888
Apr 3rd, 2004, 11:12 PM
I was wondering what the difference between my code above and yours?
VBE.VBProjects.Item("project").VBE.CodePanes.Item(1).ShowThey both do the same, but mine opens any named module or classe and yours can only open the
module or class that the function is in.
TheFIDDLER
Apr 4th, 2004, 09:19 PM
I can't seem to get your bit of code to work for me in 97 or 02.
I keep getting an object required error message.
Did you add any specific project references to get it to work?
RobDog888
Apr 4th, 2004, 11:28 PM
No. but I am running Office 2003. Perhaps that is why?
RobDog888
Apr 5th, 2004, 09:28 PM
Just double checked, I do have the reference "Microsoft Visual
Basic for Applications Extensibility 5.3" selected.
:blush:
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.