0
我想通過PowerShell腳本接收一些數字值到Excel工作表。我已經可以將值返回,但它以字符串的形式到達電子表格,並且Excel不會允許我將其轉換爲數字。 我希望我只是錯過了一步,這不是不可能的。從PowerShell發送數值到VBA
這是VBA部分
strCommand = (PsCommand)
Set wshshell = CreateObject("WScript.Shell")
Set WshShellexec = wshshell.Exec(strCommand)
stroutput = WshShellexec.StdOut.ReadAll
Sheets("Sheet1").Cells(i, 2).Value = stroutput
Sheets("Sheet1").Cells(i, 2).NumberFormat = "0"
我的猜測是,這現在的問題是:
Set WshShellexec = wshshell.Exec(strCommand)
'Exec'異步運行命令,但是因爲'ReadAll'被阻塞,所以這裏不應該是個問題(除非外部命令產生過多的輸出,所以緩衝區被填滿了)。什麼是'PsCommand'? –
'.Value = Val(stroutput)'? – Slai
PsCommand =「Powershell -File c:\ script \ FolderSizeCheck \ FolderSizev2.ps1」&TargetFolder – Grizli