Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default 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   Report Post  
Posted to microsoft.public.excel.programming
job job is offline
external usenet poster
 
Posts: 1
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 550
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 550
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 550
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 550
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 550
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Stop Excel from automatically opening the last file esilverb Excel Discussion (Misc queries) 1 May 27th 09 04:31 PM
Opening an Excel file with macro Johan_vl2431 Excel Discussion (Misc queries) 0 May 1st 07 02:57 PM
automatically opening an excel file on startup NanTan Excel Discussion (Misc queries) 3 November 10th 06 07:55 PM
Automatically run macro when opening file Chris Excel Programming 5 December 23rd 03 02:55 PM
Opening text file in Excel through macro Ed[_9_] Excel Programming 0 October 7th 03 04:13 PM


All times are GMT +1. The time now is 03:11 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"