Running a Macro directly from the desktop


Thread Starter


I have written a Macro in Excel spreadsheet to automate a task. The excel sheet that contains the macro is on an MIS pc which is a part of YOKOGAWA CENTUM CS-2 DCS, for material balancing in a polyethylene plant. I want this macro to actuate the moment I open the Excel file. I have created a short cut on the desktop and would like to run this macro from there. At present I have to open this excel file and then run this macro....

can anybody help please?


James Martin

If you know how the VB Editor works then you can record your macro and use the VB editor to view the code that was automated for you. You can now cut and paste this code to your worksheet object activate event:
Private Sub Worksheet_Activate()
End Sub
I just wonder when you posted this message... anyway here is the answer.

You should have a macro named Auto_Open. When the Excel spreadsheet is open then the control is transfered to this macro.
You have a couple of choices.

YOu can have the macro run every time you open the workbook. I this case, name the macro Auto_open,
i.e Sub Auto_Open

Or you can have the macro run every time you activate the workbook or the worksheet. This is particularly handy to display a menu (for example) that is suitable only for one worksheet.

In this case, you need to use specific macros related to the "object" meaning the workbook or the worksheet.

To get there, you need to go to the VBA Editor,(Alt-F11 from the Excel screen), find the object you want to use in the windown in the upper left side (the project view) and double click on it. Then in the right-hand window, in the drop-down on the upper left side choose the object (worksheet, for example) and in theupper right-hand side, choose the condition (Activate, for example).

You can then write or copy the doe in the shell macro .

Note that you have a wide range of conditions. (activate, deactivate, double-click, etc.) that can trigger your macro.