Autostart Macro


Posted by Doron Angel on January 19, 2002 12:05 PM

How can I AutoStart a Macro (VB Sub) every time I open an Excel (XP version) file?

Thanks in advance,

Doron.

Posted by Jacob on January 19, 2002 2:07 PM

Hi

Im not 100% sure about XP but there should be a workbook_open sub on the workbook code or something similar. Put the code there.

HTH

Jacob

Posted by Joe Was on January 20, 2002 1:33 AM

There are a lot of ways to do this.

This is one way put this in the sheet code page.


Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
If Not Intersect(Target, Selection) Is Nothing Then
If Target.Interior.ColorIndex = 34 Then
Target.Interior.ColorIndex = 0
Else
Target.Interior.ColorIndex = 34
End If
End If
End Sub

Every time you start the workbook and select a cell it will change colors, select it again and it will change back to its original color. It works by events. There are a lot of events to pick from!

Private Sub App_WorkbookOpen(ByVal Wb As Workbook)
Application.Windows.Arrange xlArrangeStyleTiled
End Sub

On a workbook open this will re-arrange the windows by title.

On older systems you can build a DOS batch file to open Excel with a default workbook and start a macro by adding the name of the macro behind the start name for Excel, but this is not done now and you must auto-run your code with an event.

You could check out the "Shell" code it lets you, start something like the windows calculator in a window on top of your default workbook, every time you start Excel? JSW

Posted by Doron Angel on January 20, 2002 10:56 AM

thanks Joe,

It seems that I am missing something here. It did not work for me at all. Should I define a special name for the module in which I write the private sub? Should I define an "environment" symbol or definition?

Doron.

Posted by Doron Angel on January 20, 2002 12:46 PM

Found it!!! sub workbook_open worked for me.

thnx!

doron :) .



Posted by Joe Was on January 20, 2002 5:43 PM

It just go's in Sheet1 and it should work, it works for me?