Close the VBE Environment

AgentSmith

Well-known Member
Joined
Mar 8, 2004
Messages
575
I have a simple macro that launches WordPad and opens a text file via the command line. Unfortunately WordPad isn't an automation server, so the only way I can think of doing formatting is via the (admittedly horrible) SendKeys command.

My problem is that if I run this macro directly from the VBE environment then the keystrokes are actually done in the VBE window rather than in WordPad. Does Excel give me a way to automatically close the VBE environment completely? I did try this:
Code:
Application.VBE.MainWindow.Close
but got some really unhelpful error message.

If not then a second best would be to figure out the the VBE environment is open and active. If so then I would bypass the SendKeys bit.

Perhaps there is a way using API calls?

Hope this makes sense. TIA.
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
I should add that I have tried using Word, but it seems to take much longer to open the document in question. Plus it seems like overkill for a simple text file.

However, it is an automation server ... :confused:
 
Upvote 0

Forum statistics

Threads
1,215,029
Messages
6,122,757
Members
449,094
Latest member
dsharae57

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