Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Automatically run a macro when opening an Excel file
Hi everyone!
I would like to know how could I run a macro automatically when a user opens an Excel file. That is, when someone doubleclick the file on the desktop (for example), the file opens and runs a specified macro. Thanks in advance! Raphael |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Automatically run a macro when opening an Excel file
you simply have to implement the function Open of your
workbook, and call your macro as following Private Sub Workbook_Open() Call yourMacro End Sub -----Original Message----- Hi everyone! I would like to know how could I run a macro automatically when a user opens an Excel file. That is, when someone doubleclick the file on the desktop (for example), the file opens and runs a specified macro. Thanks in advance! Raphael . |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Automatically run a macro when opening an Excel file
Raphael,
The easiest way to do it would be to rename your macro as Auto_Open Sub Auto_Open() ' your code End Sub John "Raphael Saddy" wrote in message ... Hi everyone! I would like to know how could I run a macro automatically when a user opens an Excel file. That is, when someone doubleclick the file on the desktop (for example), the file opens and runs a specified macro. Thanks in advance! Raphael |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Automatically run a macro when opening an Excel file
Hi!
Thank you all for your quick answer! Really great! Would it be possible to run a macro when the user closes the file? I mean, when he closes the file, this macro would run a code to undo everything that the opening macro did. Sorry not to have asked that before! Thanks in advance. Raphael *** Sent via Developersdex http://www.developersdex.com *** Don't just participate in USENET...get rewarded for it! |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
Automatically run a macro when opening an Excel file
Raphael,
Yes, you can run a macro just before the file is closed. You'll need to use the Workbook_BeforeClose event. From the VBA editor, double click on "ThisWorkbook" in the "Projects" window and paste the following into the pane on the right: Private Sub Workbook_BeforeClose(Cancel As Boolean) ' your macro here End Sub BUT!!!!!!! It's probably not the "Close" event that you want. Remember that when you open a workbook, you're only placing a copy of that workbook into memory. What you started with is still unchanged on your hard drive. You can run your macros, do whatever you want but if you close without saving, your saved copy doesn't change. If you are saving and want to clear your stuff out, you might want to use the Workbook_BeforeSave Event. Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean) ' your macro here End Sub John "Raphael Saddy" wrote in message ... Hi! Thank you all for your quick answer! Really great! Would it be possible to run a macro when the user closes the file? I mean, when he closes the file, this macro would run a code to undo everything that the opening macro did. Sorry not to have asked that before! Thanks in advance. Raphael *** Sent via Developersdex http://www.developersdex.com *** Don't just participate in USENET...get rewarded for it! |
#6
Posted to microsoft.public.excel.programming
|
|||
|
|||
Automatically run a macro when opening an Excel file
John,
EXCELENT! EXCELENT! EXCELENT! You have helped me very very much!!!!! Thank you! Hope you have a very special year in 2004.... Bye. raphael *** Sent via Developersdex http://www.developersdex.com *** Don't just participate in USENET...get rewarded for it! |
#7
Posted to microsoft.public.excel.programming
|
|||
|
|||
Automatically run a macro when opening an Excel file
Raphael,
Happy to have been a help. Thanks for posting back. John "Raphael Saddy" wrote in message ... John, EXCELENT! EXCELENT! EXCELENT! You have helped me very very much!!!!! Thank you! Hope you have a very special year in 2004.... Bye. raphael *** Sent via Developersdex http://www.developersdex.com *** Don't just participate in USENET...get rewarded for it! |
#8
Posted to microsoft.public.excel.programming
|
|||
|
|||
Automatically run a macro when opening an Excel file
Hi John!
Once more I need your knowledge... sorry about that! :) Remember the macro you sent me? Sub Auto_Open() Application.DisplayFullScreen = True End Sub Private Sub Workbook_BeforeClose(Cancel As Boolean) Application.DisplayFullScreen = False End Sub I would like to do the following: when the user opens the file, it opens in full screen. When he closes the file, the full screen mode turns off. This two macros works just fine, except for the fact that when the user clicks on the Cancel button when Excel asks for saving the file, the full screen turns off and he goes back to the file, with all features and commands. My question is: is there a way to let the full screen activated even when the user clicks on the cancel button in the save window? Thanks once more! Raphael *** Sent via Developersdex http://www.developersdex.com *** Don't just participate in USENET...get rewarded for it! |
#9
Posted to microsoft.public.excel.programming
|
|||
|
|||
Automatically run a macro when opening an Excel file
Raphael,
There are a couple of things that you could do. One (if you don't need them to save the file) would be to turn off the alert (place at the top of your Before_Close event). Application.DisplayAlerts = False or you could fool the Workbook into thinking it's already saved (whether it has been, or not). ThisWorkbook.Saved = True John "Raphael Saddy" wrote in message ... Hi John! Once more I need your knowledge... sorry about that! :) Remember the macro you sent me? Sub Auto_Open() Application.DisplayFullScreen = True End Sub Private Sub Workbook_BeforeClose(Cancel As Boolean) Application.DisplayFullScreen = False End Sub I would like to do the following: when the user opens the file, it opens in full screen. When he closes the file, the full screen mode turns off. This two macros works just fine, except for the fact that when the user clicks on the Cancel button when Excel asks for saving the file, the full screen turns off and he goes back to the file, with all features and commands. My question is: is there a way to let the full screen activated even when the user clicks on the cancel button in the save window? Thanks once more! Raphael *** Sent via Developersdex http://www.developersdex.com *** Don't just participate in USENET...get rewarded for it! |
#10
Posted to microsoft.public.excel.programming
|
|||
|
|||
Automatically run a macro when opening an Excel file
Hi John!
Sorry to answer so late! Thank you once more for your help!!!!! Bye, Raphael *** Sent via Developersdex http://www.developersdex.com *** Don't just participate in USENET...get rewarded for it! |
#11
Posted to microsoft.public.excel.programming
|
|||
|
|||
Automatically run a macro when opening an Excel file
Raphael,
Sorry to answer so late! Not a problem. Glad to hear that it worked. John "Raphael Saddy" wrote in message ... Hi John! Sorry to answer so late! Thank you once more for your help!!!!! Bye, Raphael *** Sent via Developersdex http://www.developersdex.com *** Don't just participate in USENET...get rewarded for it! |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Stop Excel from automatically opening the last file | Excel Discussion (Misc queries) | |||
Opening an Excel file with macro | Excel Discussion (Misc queries) | |||
automatically opening an excel file on startup | Excel Discussion (Misc queries) | |||
Automatically run macro when opening file | Excel Programming | |||
Opening text file in Excel through macro | Excel Programming |