0

I created sample VBA function in .xlam module and I want to return simple Powershell Get-Date string:

Private Function test1() As String
    test1 = Shell("Powershell Get-Date")
End Function

In Excel's cells when I try to run that =test1() there are 4 digits numbers:

1456
1296
4228
1232
4976
5328
4844
4560
2572

How can I do that?

1 Answer 1

2

As documented, Shell() doesn't return the output of the external command, but its task ID. See this answer to a similar question if you want to read the command output.

If you just want to get a string with the current timestamp: there's no need to shell out to PowerShell for that. Something like this should work just fine:

Private Function test1() As String
  test1 = CStr(Now)
End Function
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.