Getting "Expected Next" error on VBscript

Status
Not open for further replies.
I'm running into an issue with a VBscript I have built. The script is Designed to find a file with a similar name to another file and move it to a specific location. The code is below:

Code:
FileName = Inputbox("Enter File Name")
ExportPath = "C:\group\YRC\export"
SearchLocation = "C:\group\YRC\export"
 
Set fso = CreateObject("scripting.filesystemobject")
Set oShell = CreateObject("Wscript.Shell")
Set sLocation = fso.Getfolder(SearchLocation)
Set BaseFileInfo = fso.GetFile(ExportPath & "\" & FileName)
 
 
For each oFile in sLocation.Files
        sName = fso.getfilename(oFile)
        SearchName = Right(sName, Len(Filename))
        Set SearchFileInfo = fso.Getfile(SearchLocation & "\" & sName)
        If SearchName = FileName Then
                If SearchFileInfo.Size >= BaseFileInfo.Size Then  fso.MoveFile Searchlocation & "\" & sName, ExportPath & "\" & sName
                Else MsgBox("File is not yet Processed")
                End If
        Else Msgbox("No File Found")
        Next
       
 
 
Msgbox("Complete")

This was working until I added the ifs and elses. If I don't use the if else statements it works but when I do have them, it gives me an error at the second else. The error is "Expected 'Next'". This is obviously a problem with my if else statements, but I don't know why they aren't getting along with the "Next". Does anyone know what I'm doing wrong here?
 
You're right that I'm. Missing an end if, but that didn't solve it,
Code:
FileName = Inputbox("Enter File Name")
ExportPath = "C:\group\YRC\export"
SearchLocation = "C:\group\YRC\export"
 
Set fso = CreateObject("scripting.filesystemobject")
Set oShell = CreateObject("Wscript.Shell")
Set sLocation = fso.Getfolder(SearchLocation)
Set BaseFileInfo = fso.GetFile(ExportPath & "\" & FileName)
 
 
For each oFile in sLocation.Files
        sName = fso.getfilename(oFile)
        SearchName = Right(sName, Len(Filename))
        Set SearchFileInfo = fso.Getfile(SearchLocation & "\" & sName)
        If SearchName = FileName Then
                If SearchFileInfo.Size >= BaseFileInfo.Size Then  fso.MoveFile Searchlocation & "\" & sName, ExportPath & "\" & sName
                Else MsgBox("File is not yet Processed")
                End If
        Else Msgbox("No File Found")
        End If
        Next
       
 
 
Msgbox("Complete")

This still results in the expected next error.
 
arthur barnhouse":1axhwbpz said:
You're right that I'm. Missing an end if, but that didn't solve it,
Code:
FileName = Inputbox("Enter File Name")
ExportPath = "C:\group\YRC\export"
SearchLocation = "C:\group\YRC\export"
 
Set fso = CreateObject("scripting.filesystemobject")
Set oShell = CreateObject("Wscript.Shell")
Set sLocation = fso.Getfolder(SearchLocation)
Set BaseFileInfo = fso.GetFile(ExportPath & "\" & FileName)
 
 
For each oFile in sLocation.Files
        sName = fso.getfilename(oFile)
        SearchName = Right(sName, Len(Filename))
        Set SearchFileInfo = fso.Getfile(SearchLocation & "\" & sName)
        If SearchName = FileName Then
                If SearchFileInfo.Size >= BaseFileInfo.Size Then  fso.MoveFile Searchlocation & "\" & sName, ExportPath & "\" & sName
                Else MsgBox("File is not yet Processed")
                End If
        Else Msgbox("No File Found")
        End If
        Next
       
 
 
Msgbox("Complete")

This still results in the expected next error.

Shouldn't that be:
Code:
Next oFile
 
Status
Not open for further replies.