Invalid Outside Procedure (Date, Time, Format, etc...)

  • Thread starter Thread starter Olda
  • Start date Start date
O

Olda

Hi,

I have just install new version MS Office 2007, but I have problems with
internal functions (Date, Time, Format, etc...):

Option Explicit
Dim MyDate
MyDate = Date ' MyDate contains the current system date.

When I compile this code, system return error "Invalid Outside Procedure".

Can you help me?

Thank you, Olda
 
Olda said:
I have just install new version MS Office 2007, but I have problems with
internal functions (Date, Time, Format, etc...):

Option Explicit
Dim MyDate
MyDate = Date ' MyDate contains the current system date.

When I compile this code, system return error "Invalid Outside Procedure".


That correct. Code only executes when it is called from
some other code procedure or when an event is triggered.

You need enclose that line in Function, End Function or Sub,
End Sub statements. Then you have to call the function or
sub from somewhere.
 
You must have a Sub or Function into which to put those code steps. They can
exist outside of a procedure (Sub or Function). For example, if you wanted
to run that code in the Load event of a form:

Option Explicit

Private Sub Form_Load()
Dim MyDate As Date
MyDate = Date
End Sub
 
Back
Top