Nilesh’s Weblog

August 12, 2008

Sleep in VBA

Filed under: Microsoft Excel — Tags: , , — deshnilesh @ 11:08 am

Here’s another known trick for VB/VBA, if you code a lot in C/Java and then switch to VB/VBA you might be surprized to know that there is no sleep function in VB. However there is a hack to implement it.

Just refer the library kernal32 for Sleep function and then use it!! Simple isn’t it?

This is what you need to put in –

Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

The function can be called as usual –

Sleep (2000)

August 4, 2008

VBA File Exists

Filed under: Microsoft Excel — Tags: , , — deshnilesh @ 2:36 pm

Couple of times I was expected to execute a code only if a particular file exists. I use to create a object of FSO and check it. However recently(was late for me though) I discovered and simple way of doing it –

If Dir("C:Testfile.xls") <> "" then
'file exists
else
'file does not exist
End if

Hope this is useful for someone.

« Newer PostsOlder Posts »

Blog at WordPress.com.