Discussion Locked

Disable the "Make *.exe" button in VB6

0 helpful
7 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.
Need to disable the button under the File menu that disables the ability to compile a program. Is there a file that controls this function - a dll or exe? What is it?

7 replies

by sl-campbell

To do this you need to create an Add-in and then register it.

Create a new VB Active-X Dll project.
Under 'Project / References' add references to:
Microsoft Visual Basic 6.0 Extensibility
Microsoft Office 8.0 Object Library
Microsoft Add-In Designer

Under 'Project / Properties' change the Project name,description and Program name to what you want to and under 'Threading-Model' select 'Single Threaded'

Under 'Project ' insert a new Add-In Class.

Rename the CLass to 'Connect'and change the 'Public' property to FALSE.
In the Add-In designer window, (double-click on the new Add-In Class 'Connect' in the Project Explorer), enter a name that is to be shown in the Add-Ins window.

In the code window add the following Code:

by sl-campbell

CONTINUED:

'START CODE BLOCK======================================

Option Explicit

Dim VBInstance As VBIDE.VBE
Dim cbFile As CommandBar
Dim cmdMnuCreateExe As CommandBarControl

Private Sub AddinInstance_OnAddInsUpdate(custom() As Variant)
'Comment to prevent removal on compilation

End Sub

Private Sub AddinInstance_OnConnection(ByVal Application As Object, _
ByVal ConnectMode As AddInDesignerObjects.ext_ConnectMode, _
ByVal AddInInst As Object, custom() As Variant)

Set VBInstance = Application

'Get the File menu.
Set cbFile = VBInstance.CommandBars("File")
Set cmdMnuCreateExe = cbFile.Controls(13)

'Disable the 'Create EXE' button in the 'File' menu.
cmdMnuCreateExe.Enabled = False

ConnectMode = vbext_cm_Startup

End Sub
Private Sub AddinInstance_OnDisconnection( _
ByVal RemoveMode As AddInDesignerObjects.ext_DisconnectMode, _
custom() As Variant)

' Enable the 'Create EXE' button in the 'File' menu.
'cbFile.Controls(cmdMnuCreateExe.Caption).Enabled = True

' release the object variable
Set cmdMnuCreateExe = Nothing

Set cbFile = Nothing
Set VBInstance = Nothing
End Sub

Private Sub AddinInstance_OnStartupComplete(custom() As Variant)
'Comment to prevent removal on compilation
End Sub

'END CODE BLOCK=========================================

Compile the DLL.
This will also register the Add-In.

Then look for the VBAddin.Ini file in the Windows directory, open it with NotePad and add then line the name of your new DLL with the property 'Connect' set to 1, (MyDll.Connect=1).

Then copy the Dll into the Windows System directory and reboot, or register it yourself.

by sl-campbell

CONTINUED:

You can restore everything by Enabling the MENU in the OnDisconnection, or delete the Dll, change the VBAdd.Ini back to how it was, and delete the registry key for this dll under:
HKEY_CURRENT_USER / Software / Microsoft / Visual Basic / 6.0 / Addins

by sl-campbell

I forgot to mention:
After you add the reference: 'Microsoft Add-In Designer' you need to select the 'Addin Class' Designer under:
'Project / Components' on the 'Designer' tab.

This discussion is closed to new replies.