If something only works when you step through the code line by line,
it is usually a timimg issue. You are likely to be allowing other
processes to complete before your next line executes. The same thing
can be achieved in code with the DoEvents keyword, which should appear
regularly in your code anyhow. If you need a longer pause in
execution, look at the Sleep Windows API.