AutoRun a Macro in Excel based on sheet name

Closed
DebP - Apr 2, 2012 at 07:34 AM
rizvisa1 Posts 4478 Registration date Thursday January 28, 2010 Status Contributor Last seen May 5, 2022 - Apr 4, 2012 at 06:08 PM
Hello,

I use the personal.xls which has many macros incorporated into it with shortcut names. The application I use that opens Excel names the sheets with the shortcut so the user can run the macro associated with the type of report. I would like to automate the process to allow the auto_run the macro based on the name of the Excel worksheet.

Is there a simple way to do this? I appreciate any assistance.



Related:

1 response

rizvisa1 Posts 4478 Registration date Thursday January 28, 2010 Status Contributor Last seen May 5, 2022 766
Apr 2, 2012 at 06:23 PM
not sure what exactly was question, but how about in same auto_open you have a bunch of if statement that can execute the macro you want
0
Sorry if I was unclear. I have several different macros that a user can run and they are stored in the startup folder for users for ease of use. I name the sheet in an outside application with several reporting options which brings the output in Excel with the different shortcut keys as the sheet name. I know it should be simple but I am having trouble with auto running a macro based on the sheet name. Do you have a quick example I could try? I really appreciate it.
0
rizvisa1 Posts 4478 Registration date Thursday January 28, 2010 Status Contributor Last seen May 5, 2022 766
Apr 3, 2012 at 06:20 AM
what you meant by "auto running". By that do you mean to say that when the workbook is opened, depending the name of the sheet in the book, a certain macro should run ? This is what I understood.
1. You have a personal.xls
2. you have some excel workbook that has one sheet in it with a certain name on it.
3. when a user open that excel workbook, you want some specific macro to run from personal.xls and which macro would be run would be based on the name of the sheet in workbook that was created by some other application
is that so ?
0
1. I have several macros stored and available to users via the startup folder
2. I have an outside application which generates reports in Excel. The outside app allows me to name the worksheet so I name it with the shortcut key of the macro for ease of use.
3. I would like to have the macro automatically run when the report comes into Excel without user input.
I appreciate any assistance you can provide -- I know I have been unclear -- If there is anyway some sample code I could work with could be provided, that would be wonderful. Thanks again.
0
rizvisa1 Posts 4478 Registration date Thursday January 28, 2010 Status Contributor Last seen May 5, 2022 766
Apr 3, 2012 at 05:58 PM
I am not sure it will work or not, But I would start by putting In your personal.xls. use this

Private Sub Workbook_Open()

Select Case (ActiveSheet.Name)
Case Is = "abc"
Call macroABC

Case Is = "xyz"
Call macroXYZ

End Select
End Sub
0
rizvisa1 Posts 4478 Registration date Thursday January 28, 2010 Status Contributor Last seen May 5, 2022 766
Apr 3, 2012 at 06:01 PM
but if have different sort of xls file in xlstart folder and you want to run once of those, I am not sure how you would do that.
0