-2

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)?

braX
  • 11,506
  • 5
  • 20
  • 33
  • You would have to read the text file (presumably from VBA) after it is created. There is no command line option for writing to an Excel worksheet. – braX Oct 06 '20 at 17:35
  • [Maybe this is what you're looking for.](https://stackoverflow.com/questions/2784367/capture-output-value-from-a-shell-command-in-vba) – ENIAC Oct 06 '20 at 17:45

1 Answers1

1

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