Candyman8019
Well-known Member
- Joined
- Dec 2, 2020
- Messages
- 1,082
- Office Version
- 365
- Platform
- Windows
I'm going to start by making it clear I know nil about powershell... I'm trying to create a script that will change the CreationDate of a single file. The odd thing is that if I paste the generated command directly into Powershell it works perfect...but if I run it from VBA, it fails. Code and screenshot of error attached. It seems as though it doesn't like the timestring. I have tried separating it from the date with a 'T'. No change. Any ideas would be appreciated.
Thanks.
Joe
VBA Code:
Public Sub CHCreateDate()
Dim PScomm As String
Dim fpath As String
Dim newCreateDateTime As String
fpath = Range("PickedFile").Value
newCreateDateTime = Format(Range("CRDate").Value, "yyyy-mm-dd") & Format(Range("CRTime").Value, "hhmmss")
PScomm = "(Get-Item " & fpath & ").CreationTime = (Get-Date(""" & newCreateDateTime & """))"
'PScomm generates this: (Get-Item C:\Users\jrieger\Desktop\1014AM\Temp\273.xlsx).CreationTime = (Get-Date("2015-01-12 19:14:25"))
CreateObject("Wscript.Shell").Run "powershell.exe -ExecutionPolicy Bypass -command " & PScomm, windowStyle:=WshHide, waitOnReturn:=True
End Sub
Thanks.
Joe