Hi,
You can't put any old code in the ThisWorkbook module and expect it to run when the workbook opens: you have to specifically tell Excel that you want it to run when the workbook opens.
An Excel workbook has a Workbook_Open() event handler: this is the VBA code it will run when the workbook is opened. In the visual basic editor, double click on the ThisWorkbook module in the project explorer. Then, just above the code pane you'll notice two dropdown boxes (see picture). In the left hand one choose workbook. In the right hand one choose Open (you don't actually need to do this because the Workbook_Open() event handler will be automatically chosen for you) - while you're there have a look at some of the other Workbook event handlers which are available because they might be useful for you in the future. Once this is done, a Workbook_Open() event handler will be created for you in the code pane. You can put whatever code you want to run inside it, or you can call your existing procedure from it.
|