【问题标题】:From VBA to CMD - how insert result of command to cell [duplicate]从VBA到CMD - 如何将命令结果插入单元格[重复]
【发布时间】:2021-01-21 15:22:08
【问题描述】:

在单元格 (1, 1) 中,我将方式粘贴到文件中。

Sub Command()

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

当我按下运行按钮时,宏会打开命令提示符并使用命令“certutil -hashfile”。 但我可以创建只能将结果保存到文本文件的宏。 是否可以将命令提示符的结果写入单元格? 或者用这个带有宏 *\files.txt 的 xls 将 txt 文件的目录更改为 * 文件夹(如果我用 xls 和 txt 文件替换文件夹)?

【问题讨论】:

标签: vba cmd certutil


【解决方案1】:

可以找到答案。

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-25
    • 2021-12-17
    • 2016-06-20
    • 2012-08-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多