Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

code won't run in VBS, but ok in macro 1

Status
Not open for further replies.

JustineB

Programmer
Mar 30, 2001
165
0
0
GB
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
 
Format isn't implemented in VBS.
Replace this:
Format(Now, "yyyy_mm_dd")
with this:
Year(Now) & "_" & Right("0" & Month(Now),2) & "_" & Right("0" & Day(Now),2)

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thank you so much! I've not done any coding for a long time, hard to get my head back into it! Hopefully there won't be too much more :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top