close the Visual Basic Editor Window

Eddie G.

Board Regular
Joined
Feb 27, 2002
Messages
98
i have a macro that deletes all other macros in a workbook. I run this macro from the VBE after manually deleting for forms. I need to put a line in the code that closes the Visual Basic Editor Window. I tried application.VBE.MainWindow.Close and I get an error message. Any ideas?
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
This function will try and close Excel when stepping through your code in break mode. If called fro another procedure, then it seems to work fine. Is actually for Access.
<pre>Private Const WM_CLOSE = &H10

Private Declare Function apiPostMessage _
Lib "user32" Alias "PostMessageA" _
(ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
lParam As Any) _
As Long

Private Declare Function apiFindWindow _
Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) _
As Long

Private Declare Function apiIsWindow _
Lib "user32" Alias "IsWindow" _
(ByVal hwnd As Long) _
As Long

Function fCloseVBEWindow() As Boolean

Const VBE_CLASS = "wndclass_desked_gsk"
Dim hwnd As Long
hwnd = apiFindWindow(VBE_CLASS, Application.VBE.MainWindow.Caption)
If hwnd Then
Call apiPostMessage(hwnd, WM_CLOSE, 0, 0&)
fCloseVBEWindow = (apiIsWindow(hwnd) <> 0)
End If
Application.SendKeys "~"
End Function

Sub CloseItUsage()
If fCloseVBEWindow Then
MsgBox "VBE closed"
Else
MsgBox "Failed to clode VBE"
End If
End Sub

</pre>
tom
 
Upvote 0
Try:

Sub CloseMainWindow()
Application.VBE.MainWindow.Visible = False
End Sub

Sub OpenMainWindow()
Application.VBE.MainWindow.Visible = True
End Sub
 
Upvote 0
I have the same problem

I have tried both the above to close the window but it keeps coming up with an error.

anyone else got any ideas.

i've tried nearly all the

application.vbe. (options)

there must be some way of doing it
 
Upvote 0
found a way of doing it

Here is the code

ThisWorkbook.VBProject.VBE.MainWindow.Visible = False

insert this after the add script to sheet section.

i placed it in thisworkbook after i had called the procedure to add the script to the createdsheet.
:)
 
Upvote 0
Eddie G,

Welcome to the board. You wouldn't be interested in posting your code for deleting the other macros you mentioned, would you? I've been trying to come up with a macro-blaster that works, but have been stymied (with nothing in this forum but dead ends). I'd appreciate it no end.

Thanks,
Jim
 
Upvote 0
Just in case someone is coming the to this old thread as I did: If you are looking for a comprehensive solution for how to export, import, remove, transfer, synchronize any Code Module - even ThisWorkbook and Worksheet code - than you may have a look at Multiple Code Module Management. I've spent more than hundred hours on this to get it working smothly and save, still keeping it updated - and I am using it to transfer its own code from the development version to the test version to the productive version.

 
Upvote 0

Forum statistics

Threads
1,213,497
Messages
6,113,999
Members
448,543
Latest member
MartinLarkin

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top