I tried writing a vba password cracker code similar to the code I used to crack Excel sheet\'s password But I am not sure if I am doing correctly or not - when i tried this code
The reason your code is not executing properly is because you are attempting to execute a macro on a password protected execel file, which is not permitted. This is due to the fact that macros will not execute on an excel workbook until the password is entered - thus the prompt for a password before you can execute your macro code.
This SO article explains this as well, with greater detail: Excel VBA - Automatically Input Password
EDIT
For 2003
If you are trying to access the workbook, not the worksheet, there are a variety of ways in versions 2003 and earlier. After a quick perusual, this blogspot Code Samples entry appears to have a working version for unprotecting a 2003 workbook.
Also, on a related note, if you are stepping back even further and trying to unlock a VBA project, this SO article appears to adequately address the issue.
For 2007
If you are simply trying to "brute force" unprotect a client's workbook, a gentleman named Jason has outlined such a process in his blog.