Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Run a macro each time a workbook is saved

Hi everybody,
I would like to know how to run a macro any time a workbook is bein
saved. I created my macro is saved in "Personal.xls" but I do not kno
how to trigger it without using a button associated to it but instea
when the user would click File-save or directly the save icon. I trie
to add a call to my macro in the code of the event BeforeSave o
"Personal.xls" but it does not work...

Thanks to whoever can give me a hand on this.

donbu

--
Message posted from http://www.ExcelForum.com

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Run a macro each time a workbook is saved

You will need to create class event to trap the event of any open workbook
being saved.
The class event can reside in your personal.zls.

A good resource to read up on this is in chip pearson web site.
url I think is www.cpearson.com

as well do a googgle search on class events.

to get you started.....
Put the following in a new class module
' use insert class module from vbe

rename it to EventClass

Option Explicit
Public WithEvents App As Application

Private Sub App_WorkbookBeforeSave(ByVal wb As Workbook, Cancel As Boolean)
' your code
end sub


In this thisworkbook module of personal.xls
Option Explicit
Dim AppClass As EventClass

Private Sub Workbook_Open()
Set AppClass = New EventClass
Set AppClass.App = Application
End Sub


Private Sub Workbook_BeforeClose(Cancel As Boolean)
Set AppClass.App = Nothing
End Sub


"donbuz " wrote in message
...
Hi everybody,
I would like to know how to run a macro any time a workbook is being
saved. I created my macro is saved in "Personal.xls" but I do not know
how to trigger it without using a button associated to it but instead
when the user would click File-save or directly the save icon. I tried
to add a call to my macro in the code of the event BeforeSave of
"Personal.xls" but it does not work...

Thanks to whoever can give me a hand on this.

donbuz


---
Message posted from http://www.ExcelForum.com/



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Run a macro each time a workbook is saved

Great answer quick & accurate, thx a lo

--
Message posted from http://www.ExcelForum.com

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
Changes to workbook not saved Jill Valentine Excel Discussion (Misc queries) 1 August 31st 07 02:56 PM
The time the spreadsheet was saved Cheryl Excel Discussion (Misc queries) 1 November 22nd 06 07:17 PM
Macro run each time a new workbook created cmorton89 Excel Discussion (Misc queries) 0 March 8th 06 07:58 PM
How can I see a copy of a saved workbook before I saved it again? Norma Excel Worksheet Functions 2 May 11th 05 10:31 AM
macro to time limit workbook ditchy Excel Discussion (Misc queries) 5 April 26th 05 08:43 AM


All times are GMT +1. The time now is 05:37 AM.

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

About Us

"It's about Microsoft Excel"