Auto_open functionality

brindle1121

New Member
Joined
Feb 25, 2009
Messages
4
I keep reading that auto_open is not a preferred, modern method and that it is retained for backwards compatibility purposes only. But auto_open is the only way I've found (so far) to trigger an XL event when a module opens in my application.

I have an application where the event detection trigger needs to be (seemingly) placed in a module. This is because the module's code is copied into the new workbook from a xxx.bas file located elsewhere. The IMPORT instruction.

application.vbe.activevbproject.vbcomponents.import c:\....

copies the file into the new module properly. (I have not found a way to copy code from an external source into a workbook or worksheet specific module).

When the new workbook opens, only the auto_open code creates an event. Workbook_open and Spreadsheet_open do not function in a module.

Is there another way to do this?
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
I may be wrong but is this what you are looking for.

1) Open New Excel File. Press F11 to goto VB Editor.
2) Select ThisWorkbook. In the drop downs select the event to - Workbook - Open. Type the code given below.
3) Make sure that the file c:\temp\script.bas exist which you want to automatically import when this file is opened.
4) Save the file and close it.
5) Try opening it again. The module script.bas should be automatically imported.

Code:
Private Sub Workbook_Open()
    Application.VBE.activevbproject.VBComponents.Import "c:\temp\script.bas"
End Sub
 
Upvote 0
Welcome to the Board!

The Workbook_Open event needs to go in the ThisWorkbook module, not a general module.

HTH,
 
Upvote 0

Forum statistics

Threads
1,215,133
Messages
6,123,232
Members
449,092
Latest member
SCleaveland

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