Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
|
|||
|
|||
![]()
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
|
|||
|
|||
![]()
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
|
|||
|
|||
![]()
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
|
|||
|
|||
![]()
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
|
|||
|
|||
![]()
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
|
|||
|
|||
![]()
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! |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
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 |