CodeModule.CreateEventProc and .InsertLines only executing when VB Editor is open

counterS

New Member
Joined
Mar 14, 2016
Messages
2
I am trying to Create the Open Workbook Event in anohter Workbook. Everything works fine while the VB Editor is open. If I exit out of the File and open it (with VBEditor closed) it returns error 57017.

It is very confusing that VBA functions exist which seem to require the VBEditor to be open. I tried to search for similiar Problems, but couldn't find a solutions for it.

Is it possible to run these functions without opening the VBEditor?

Another thing I tried is opening the Editor before calling the functions and closing it after using Application.VBE.MainWindow.Visible = true, but it seems that the window isn't opnening immediatly so the code is run before the Editor is open. An awkward solution would be to open the Editor wayyyy before, for example on opening the whole workbook, which is not the optimal solution.

As far as it seems CreateEventProc is the only method to Insert Event code into a file aswell, so there is no alternative.
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().

Forum statistics

Threads
1,223,723
Messages
6,174,121
Members
452,545
Latest member
boybenqn

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