Reputation: 5
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
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