Autorunning Macros

  • Thread starter That's Confidential
  • Start date
T

That's Confidential

I have the following Macro set up in a workbook:-

Sub datechk()
Application.ScreenUpdating = False
For a = 1 To ActiveSheet.UsedRange.SpecialCells(xlLastCell).Row
If Cells(a, 4).Value < Date Then GoTo hit
Next a
MsgBox ("Accounts appear to be in order")
Application.ScreenUpdating = True
Exit Sub
hit:
MsgBox ("You have some accounts to be deleted!")

Application.ScreenUpdating = True
End Sub


To run this Macro, I have shortcuted it as Ctrl + Q.

Is there any way I can get this Macro to run automatically on opening the
workbook?
 
D

Don Guillett

right click the excel icon to the left of file>view code>left window
worksheet>right window open>
 
T

Toby Erkson

Huh? I got as far as View Code then got lost.

TC-
Open the VBA editor and click on ThisWorkbook. Paste the below code in the
editor window:
Private Sub Workbook_Open()
Call datechk() ' This is where you put your code to execute when the
workbook Opens
End Sub

Nice and simple :)
 
G

Gord Dibben

Toby

Don's right-click on the Excel icon and "view code" puts you in the
ThisWorkbook module.

In the left-hand dialog box(general or workbook choices), click "Workbook".
The WorkBook_Open sub/End sub code lines will appear. See right-hand dialog
box for other choices.

Gord Dibben Excel MVP
 
Top