Excel VBA Course
Excel VBA Course - From Beginner to Expert

200+ Video Lessons
50+ Hours of Video
200+ Excel Guides

Become a master of VBA and Macros in Excel and learn how to automate all of your tasks in Excel with this online course. (No VBA experience required.)

View Course

Useful addition to "Run a Macro at a Certain Time" tutorial?

0

Dan

Thanks for the recent tutorial "Automatically Run a Macro at a Certain Time: Run a Macro at 4:30PM every day". Very useful.

I think that macro only works if the workbook remains open. Therefore I've added a Close macro (also to VBA's ThisWorkbook) to prevent it being closed accidentally. Ny simple coode is as follows (apologies for not declaring the variable!):

Private Sub Workbook_BeforeClose(Cancel As Boolean)
'
'Warn user that there's a timed macro running

r = MsgBox("Want to close workbook '" & Me.Name & "' (and prevent the timed macro(s) from running)?", vbYesNo)
If r = vbNo Then Cancel = True

End Sub

Might that be useful for other less-experienced coders?

John

Answer
Discuss

Discussion

Thanks for the tip! I will move this post to the Members Discussion forum soon.
I don't currently have a big link to that forum on the site just because people would ask Excel questions there.

And soon, I want to have up and running a way that you could submit that as another macro to show on the site, but I'm still working on how to allow users to do that.
don (rep: 1989) Oct 12, '16 at 7:39 pm
Thanks Don. I didn't know about "Application.OnTime" until I read your tutorial but then wanted to find how to ensure it would run a specific macro (to launch a trafiic webite, ahead of my normal departure time from work).

I guess adding a feature for members to contribute macros to your site has a risk that someone might introduce malicious code. Hopefully that never happens.

Wasn't sure where to post such things but will add to the Menber Forum in future.

Thanks again for all the weekly tips- I find them a fun and easy way of learning more about the breadth and power of both Excel and VBA. Cheers!

John
John_R (rep: 9) Oct 13, '16 at 3:13 am
Yea, I will have to look through the code for each submission until we can get some verified or trusted users who are submitting content but, eventually, I think it could be a great system because I obviously can't add as much content myself as a whole community of users could and I HATE the websites that charge to download macros. I don't mind charging for premium content but I don't think general macros and text-based tutorials should be included in that.
don (rep: 1989) Oct 13, '16 at 12:11 pm
Add to Discussion



Answer the Question

You must create an account to use the forum. Create an Account or Login