Hi folks
This code runs fine in Excel macro, but I cannot get it to work in VBS.
can anyone tell me what's wrong with it?
Many thanks in advance.
J
Sub FileRename()
Dim OldPath 'As String
Dim NewPath 'As String
Dim FileExt 'As String
Dim FileNames 'As String
Dim FileSysObj 'As Object
Dim NewFolder
OldPath = "C:\Users\JBinnall\OLD"
NewPath = "C:\Users\JBinnall\OLD\TDH_" & Format(Now, "yyyy_mm_dd") & "\"
FileExt = "*.txt*"
If Right(OldPath, 1) <> "\" Then
OldPath = OldPath & "\" & FileExt
End If
'FileNames = Dir(OldPath & FileExt)
Set FileSysObj = CreateObject("Scripting.FileSystemObject")
Set NewFolder = FileSysObj.CreateFolder(NewPath)
FileSysObj.MoveFile OldPath, NewFolder
End Sub
This code runs fine in Excel macro, but I cannot get it to work in VBS.
can anyone tell me what's wrong with it?
Many thanks in advance.
J
Sub FileRename()
Dim OldPath 'As String
Dim NewPath 'As String
Dim FileExt 'As String
Dim FileNames 'As String
Dim FileSysObj 'As Object
Dim NewFolder
OldPath = "C:\Users\JBinnall\OLD"
NewPath = "C:\Users\JBinnall\OLD\TDH_" & Format(Now, "yyyy_mm_dd") & "\"
FileExt = "*.txt*"
If Right(OldPath, 1) <> "\" Then
OldPath = OldPath & "\" & FileExt
End If
'FileNames = Dir(OldPath & FileExt)
Set FileSysObj = CreateObject("Scripting.FileSystemObject")
Set NewFolder = FileSysObj.CreateFolder(NewPath)
FileSysObj.MoveFile OldPath, NewFolder
End Sub