From VBA to CMD - how insert result of command to cell

1k views Asked by At

In cell (1, 1) I paste way to file.

Sub Command()

    Shell "cmd.exe /c CertUtil -hashfile " & Range("A1") & " SHA512 > d:\files.txt"
    
End Sub

When I push Run button, macro opens command prompt and use command "certutil -hashfile". But I can create macro which can only save the result to text file. Is it possible to write the result of the command prompt into a cell? Or change directory of txt file to * folder with this xls with macro *\files.txt (if I replace folder with xls & txt files)?

1

There are 1 answers

0
Анатолий Миронов On

Can find an answer.

Sub command()
Dim WshExec As Object
Set WshExec = CreateObject("WScript.Shell").exec("CertUtil -hashfile " & Range("A1") & " SHA512")
While WshExec.Status = 0
Wend
Range("a2") = Application.WorksheetFunction.Trim(WshExec.StdOut.ReadAll)
End Sub