Dir function and looping through all files
i have a problem with error message saying:
invalid procedure call or argument
what i'm i doing wrong as had this working fine loopng through untill added some more logic
now doesnt loop
the error is on the calling of the next file id directory see line marked ***********************
thanks ...appreciate help, need it urgently.
---------------------------
Sub Macro1()
'
' Macro1 Macro
'
'
'Messages
Dim messgeNoIAU As String
Dim messgeNolistNub As String
Dim messgeSuccess As String
Dim IUID As String
Dim logFile As String
Dim NotdoneDupTest As Boolean
Dim messgeDupliID As String
Dim dupFlag As Boolean
Dim passingfileName As String
messgeDupliID = "Practise ID is duplicated"
messgeNoIAU = "had No Practise ID"
messgeNolistNub = "had No list number"
messgeSuccess = "was sucessfully processed"
'go through all files
If FileFilter = "" Then FileFilter = "*.xls"
TargetFolder = "D:\Projects\SNE\IU's\extractedXmlFiles0600504\mar chpst\Inbox\"
fn = Dir(TargetFolder & FileFilter) ' the first file name in the folder
While Len(fn) > 0
dupFlag = False
NotdoneDupTest = True
practiseID = False
practiceListSize = False
Workbooks.Open fileName:= _
TargetFolder & fn
'GotoFirstSheet
Call GotoFirstSheet
Range("B26").Select
IUID = ActiveCell.Value
If IsEmpty(ActiveCell) Then
practiseID = False
Else
practiseID = True
End If
Range("B27").Select
If IsEmpty(ActiveCell) Then
practiceListSize = False
Else
practiceListSize = True
End If
If (practiseID = False) Then
ActiveWorkbook.SaveAs fileName:= _
"D:\Projects\SNE\IU's\extractedXmlFiles0600504\mar chpst\PractiseIDFailed\" & fn _
, FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False
logFile = "D:\Projects\SNE\IU's\naeemsFailLogFile.xls"
Call ManipulateFileName(ActiveWorkbook.Name, messgeNoIAU, logFile, IUID)
ElseIf (practiceListSize = False) Then
ActiveWorkbook.SaveAs fileName:= _
"D:\Projects\SNE\IU's\extractedXmlFiles0600504\mar chpst\practiceListSizeFailed\" & fn _
, FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False
logFile = "D:\Projects\SNE\IU's\naeemsFailLogFile.xls"
Call ManipulateFileName(ActiveWorkbook.Name, messgeNolistNub, logFile, IUID)
ElseIf NotdoneDupTest Then
dupFlag = CheckPracIDDup(ActiveWorkbook.FullName, IUID)
If dupFlag Then
ActiveWorkbook.SaveAs fileName:= _
"D:\Projects\SNE\IU's\extractedXmlFiles0600504\mar chpst\dupicateIDFailiure\" & ActiveWorkbook.Name _
, FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False
logFile = "D:\Projects\SNE\IU's\naeemsFailLogFile.xls"
Call ManipulateFileName(ActiveWorkbook.Name, messgeDupliID, logFile, IUID)
NotdoneDupTest = False
' do duplicate test
'first write all IUIDs to a file (temp checking file) ie every time u get here
'this writing will be IAU ID to file + name of file
' then check if current IAU ID already exist in list if does
'get name of file and open it saveit in Duplicate folder
'delete it from all validation passed section
'place current file also in duplicate fail folder
' log the IAU and file details in duplicate log file
' open log file of successful and search for math of IAU in 4th coloubm
' copy entire row into duplicate log file
' delete entire row from allvalidation passed
Else
ActiveWorkbook.SaveAs fileName:= _
"D:\Projects\SNE\IU's\extractedXmlFiles0600504\mar chpst\allValidationPassed\" & fn _
, FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False
logFile = "D:\Projects\SNE\IU's\naeemscompleteLogFile.xl s"
Call ManipulateFileName(ActiveWorkbook.Name, messgeSuccess, logFile, IUID)
End If
End If
ActiveWorkbook.Close
fn = Dir ' the next file name in the folder '************************
Wend
End Sub
|