Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Macros that only run once

Hi,

Is it possible to have a macro that only runs the first time a spreadsheet
is opened by the user and then never again (say to perform some cleanup and
formatting)?

Tim.


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 133
Default Macros that only run once

Yes, right click on any sheet in your file, click on View Code, then
click on "This Workbook"...in the drop down menu where it probably says
"General", you want to choose "Workbook"..then you can use the right
drop down menu to choose the On Action criteria, like "Open"...this
will then give you a macro which will run only when the file is opened

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Macros that only run once

Hi Tim

With One macro named "TheMacro" in Module1
The simplest way is to delete the entire module with contains the procedure.

Sub TheMacro()
'
' your code
'
With ThisWorkbook.VBProject.VBComponents
.Remove .Item("Module1")
End With
End Sub

But this must be checked to do this
http://www.j-walk.com/ss/excel/tips/tip96.htm


--
Regards Ron de Bruin
http://www.rondebruin.nl



"Tim Payne" wrote in message ...
Hi,

Is it possible to have a macro that only runs the first time a spreadsheet is opened by the user and then never again (say to
perform some cleanup and formatting)?

Tim.




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Macros that only run once

That's exactly what I was after! Using this I can have my spreadsheet run
some one-time initial formatting and layout macros, and then remove the
macro so that it's not run on subsequent opens of the spreadsheet. Thanks
for the advice!

:)

Tim.


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Macros that only run once

Hi tim

If you want to run the code automatic when you open the workbook
the first time than name the macro

Sub Auto_open()
'code or macro name
End Sub

Note : If you use a Auto_open macro then this wil not run if you open the file with a macro





--
Regards Ron de Bruin
http://www.rondebruin.nl



"Tim Payne" wrote in message ...
That's exactly what I was after! Using this I can have my spreadsheet run some one-time initial formatting and layout macros, and
then remove the macro so that it's not run on subsequent opens of the spreadsheet. Thanks for the advice!

:)

Tim.




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
weird saving of a document with macros resulting with macros being transfered to the copy alfonso gonzales Excel Programming 0 December 12th 04 09:19 PM
convert lotus 123w macros to excel macros rpiescik[_2_] Excel Programming 1 September 19th 04 12:41 PM
convert lotus 123w macros to excel macros rpiescik Excel Programming 1 September 18th 04 01:35 PM
Macro Size Limit / open macros with macros? andycharger[_7_] Excel Programming 6 February 13th 04 02:00 PM
Suppress the Disable Macros / Enable Macros Dialog Shoji Karai Excel Programming 5 September 24th 03 03:10 AM


All times are GMT +1. The time now is 12:35 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"