Saturday 8 April 2017

Use Shell to give you multitasking

Often on StackOverflow I see questions regarding long-running file handling using Scripting Runtime.  They really should learn to shell out to the command line, this way their VBA code does block.

So the simplest case is Shell and Forget here is some code.  You need to read the ComSpec environment variable and you need to pass the command switches /S /C.

Here we are opening the workbook's home folder in Windows Explorer.



Sub ExploreMyHomeDir()
    Shell (Environ("comspec") & " /s /c explorer.exe " & ThisWorkbook.Path)
End Sub

No comments:

Post a Comment