通过VBA在Excel中返回Powershell结果

通过VBA在Excel中返回Powershell结果,vba,powershell,excel,Vba,Powershell,Excel,我在.xlam模块中创建了示例VBA函数,并希望返回简单的Powershell Get Date字符串: Private Function test1() As String test1 = Shell("Powershell Get-Date") End Function 在Excel的单元格中,当我尝试运行 =test1() 有4位数字: 1456 1296 4228 1232 4976 5328 4844 4560 2572 如何执行此操作?因为,Shell()不返回外部命令的

我在.xlam模块中创建了示例VBA函数,并希望返回简单的Powershell Get Date字符串:

Private Function test1() As String
    test1 = Shell("Powershell Get-Date")
End Function
在Excel的单元格中,当我尝试运行 =test1() 有4位数字:

1456
1296
4228
1232
4976
5328
4844
4560
2572
如何执行此操作?

因为,
Shell()
不返回外部命令的输出,而是返回其任务ID。如果要读取命令输出,请参阅类似问题

如果您只想获得一个带有当前时间戳的字符串:那么就不需要向PowerShell支付任何费用。像这样的东西应该可以很好地工作:

Private Function test1() As String
  test1 = CStr(Now)
End Function