|
Automatically Run a Macro so Many Seconds, Minutes, or Hours After an Excel Workbook has been Opened
Run a macro after a certain amount of time has passed since the Excel workbook was opened. This means that you can set this macro to run another macro after the Excel workbook has been open for 10 seconds, 25 minutes, 1 hour, etc. This allows you to run times sensitive macros in Excel, such as time based warnings - i.e. "You have 15 minutes left for this test!" As it is now, this macro will run another macro 10 seconds after the Excel workbook that contains this macro is opened.
This macro only calls another macro in Excel. This means that you have to already have another macro which you need this macro to run at a set time length. Also, this workbook must go in the "ThisWorkbook" window for macros and not a module. In order for this macro to work, you must save and close and then reopen the workbook after this macro has been installed in the workbook. This is because this macro is triggered to run by the opening of the workbook in which it is contained.
This macro uses the Application.OnTime method in Excel. In order to modify the macro for your needs, just change Name_of_Macro to the name of the macro which you want to run. Make sure the name is exactly the same and include any require parameters for the other macro if that is needed.
Also, you need to setup the macro to run the other macro at the time interval that best suits your needs. To do this, simply change 00:00:10 in the macro below. As it is this macro will run another macro 10 seconds after the workbook is opened. The first set of zeros is for hours; the next set is for minutes; the last set if for seconds.
Where to install the macro: ThisWorkbook
Excel Macro to Automatically Run a Macro so Many Seconds, Minutes, or Hours After an Excel Workbook has been Opened
Private Sub Workbook_Open()
'Runs a macro 10 seconds after Excel is opened
Application.OnTime Now + TimeValue("00:00:10"), "Name_of_Macro"
End Sub
How to Install the Macro
- Select and copy the text from within the grey box above.
- Open the Microsoft Excel file in which you would like the Macro to function.
- Press "Alt + F11" - This will open the Visual Basic Editor - Works for all Excel Versions.
Or For other ways to get there, Click Here.
For Excel Versions Prior to Excel 2007 Go to Tools > Macros > Visual Basic Editor
For Excel 2007 Go to Office Button > Excel Options > Popular > Click Show Developer tab in the Ribbon. Then go to the Developer tab on the ribbon menu and on the far left Click Visual Basic
- On the new window that opens up, go to the left side where the vertical pane is located. Locate your Excel file; it will be called VBAProject (YOUR FILE'S NAME HERE) and click this.
- If the Macro goes in a Module, Click Here, otherwise continue to Step 8.
- Go to the menu at the top of the window and click Insert > Module
- Another window should have opened within the Visual Basic Editor's window. Within this new window, paste the macro code. Make sure to paste the code underneath the last line of anything else that is in the window.
- Go to Step 8.
- If the Macro goes in the Workbook or ThisWorkbook, Click Here, otherwise continue to Step 8.
- Directly underneath your excel file called VBAProject(your file's name here), click the Microsoft Excel Objects folder icon to open that drop-down list.
- Then, at the bottom of the list that appears, double-click the ThisWorkbook text.
- A new window inside the Visual Basic Editor's window will appear. In this new window, paste the code for the macro. Make sure to paste this code underneath the last line of any other code which is already in the window.
- Go to Step 8.
- If the Macro goes in the Worksheet Code, Click Here, otherwise continue to Step 8.
- Directly underneath your excel file called VBAProject(your file's name here), click the Microsoft Excel Objects folder icon to open that drop-down list.
- Within the list that appears you will see every worksheet that is in that excel file. They will be listed as such: Sheet1(NAME OF SHEET HERE) and under that will be Sheet2(NAME OF SHEET HERE). Select the sheet in which you want the macro to run and double-click that sheet.
- A new window inside the Visual Basic Editor's window will appear. In this new window, paste the code for the macro. Make sure to paste this code underneath the last line of any other code which is already in the window.
- Repeat steps b and c for every sheet you want the macro to work in. Putting the macro in one sheet will not enable it for any other sheets in the workbook.
- Go to Step 8.
- Close the Microsoft Visual Basic Editor window and save the Excel file. When you close the Visual Basic Editor window, the regular Excel window will not close.
- You are now ready to run the macro.
Similar Helpful Excel Resources
Hello,
I wanted to use this subroutine as a formula =TimeStamp()
The script will show the current time in hours, minutes and seconds.
Code:
Sub TimeStamp()
ActiveCell.Value = Time
ActiveCell.NumberFormat = "h:mm:ss"
End Sub
Could someone give me some help?
Thanks in advance,
grid
Hi, I've got some lists of times in hours minutes and seconds for programme transcripts starting at a random number, for example one of my lists starts at 22 minutes and 30 seconds and then will have different time codes randomly for between 25 and 45 minutes. I need to minus the first value so that all of the times start at 00.00.00. I cant figure out how to do this, have tried a few different ways but keep on getting lost!
Any ideas? Might be something really simple that I'm not thinking of?
thanks
Okay, I have a quandary, and an hour of searching did not find it. Close, but no cigar.
In a cell (we'll say A1 for simplicity), I have the following example data:
1:00:43:46 - This is to equivocate to 1 day, 00 hours, 43 minutes, and 46 seconds. I would like to express this value in seconds only.
Now, I found other threads that say to multiply the Hours/minutes/seconds value by 86400, and that works for most of our entries. However, some employees' total utilization times go over a whole day (24 hours) during the week, and we need the same results for them.
Sooo....most of the employees will show up like this - 5:12:43
But some will show up like this - 1:00:12:53
I need both results to be converted into purely seconds. Any help? We're running Office 2007, but XP answers are welcome (if different).
I have cells in a column in a worksheet that represents a number of total number of seconds allocated to a client. How can I break that number down to give me the total number of hours, minutes, and seconds?
For example, 27,607 seconds works out to be 7 hours, 40 minutes, and 7 seconds. Is it possible to run an equation off the 27,607 seconds and put the 7 in a column for hours, the 40 in a column for minutes, and the 7 in a column for seconds?
If I have A1 cell has 82.25118 how do I set up the spread sheet to place
hours (1) in cell A2
minutes (22) in cell A3
and seconds (15) in cell A4?
I have a spread sheet with a colum showing average time to complete a task. This is currently shown as Days:Hours:Minutes:Seconds (4:19:33:19). I meed it to be shown purely as minutes, or at least as hours and minutes.
Is there an easy way to do this?
How in excel do I convert 4955450 seconds into hours, minutes, and seconds in 1 formula?
Hi,
Is there an easy way of converting seconds from using a time into hours, minutes, seconds please?
I have a bunch of data that is in the following format: hours:minutes:seconds
For example:
3:23:14
5:20:45
8:10:20
How can i convert this into just minutes.
Thank You Very Much.
Is there a formula that will convert time format from minutes and seconds to Hours, minutes and seconds. I have some stats from Crystal Reports that are in minutes and seconds format (i.e 01:02, 1 minute & 2 seconds). I paste this into excel and compare the times with other stats that are in hours, minutes & seconds format (i.e 00:01:02, 0 hrs, 1 minutes & 2 seconds). At the moment I am having to overtype the cell to convert it in to the hours minutes & second format but wondered if there was a forumula I could set up that would do this for me.
|
|