Eebigdog
Eebigdog

Reputation: 5

VBA delay millisecond timer using API

I need a VBA millisecond (~100) delay timer and tried using the API:

Public Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As LongPtr)

Then use Sleep(100) in a sub.

But, when I try using it I get a compiler error:

    "Constants, fixed-length strings, arrays, user-defined types and
     declare statements not allowed as Public members of object modules"

I get the same error if I change it to 'Private'.

Any clues as to how I can get this to work? Thanks for any help provided.

Upvotes: 0

Views: 479

Answers (1)

Mathieu Guindon
Mathieu Guindon

Reputation: 71187

The relevant part of the error is this (emphasis mine):

"Constants, fixed-length strings, arrays, user-defined types and declare statements not allowed as Public members of object modules"

In other words, you apparently can't have a Public Declare statement in a class module.

Add a new standard/procedural (.bas) module, and move the Declare statement(s) there. Or, make it Private if that's the only module it's used in.

Should "just work" ;-)

Upvotes: 2

Related Questions