Search code examples
excelvbabatch-fileloggingoffice-2007

Logging Error VBA excel Batch command


I have a batch file contains

echo test string >>Log.txt 

when i click on it it will make a Log.txt file and the "test string" will be in it. But when i run the batch file from VBA excel using WScript.Shell it is not creating the Log.txt file. But the batch code is running. How can I make it working? I am using windows7 and excel 2007


Solution

  • I suggest specifying an absolute path to the file.

    echo test string >>"%USERPROFILE%\Document\Log.txt"
    

    The most common frustration I experience when using relative paths is that it's relative to the "working directory" windows uses for the calling process, and if it's launched from Explorer, that can easily be %WINDIR% or some place where you don't want stuff saved.