JazzSP8
Well-known Member
- Joined
- Sep 30, 2005
- Messages
- 1,233
- Office Version
- 365
- Platform
- Windows
Hey All
I'm trying to come up with a way of checking a folder full of Workbooks and seeing if there is a corresponding text file in another folder.
I know how to check through a folder for the Workbooks, and I know how to check to see if a file exists but I just can't get them to work together :-/
What my code attempts to do is find a Workbook name and then take a part of that Workbook name and use it to look for a text file.
Going back to basics, this is the code that I came up with originally based on what I already knew;
I'm getting the error "Invalid procedure call or argument" on;
After it's done the first loop.
I've tried various things to get it to work but all have failed, I've been working on the premise that because I use 'Dir' twice then something is going wrong.
The first Workbook gets named as I'd expect; in the test environment I've set up then the text file for this workbook doesn't exist and the Message Box gives me the name but then I get the error after that.
If I remove the IF statement then it loops through all of the Workbooks get named in my Message Box.
Any help would be much appreciated
Thanks for taking the time to look at this.
I'm trying to come up with a way of checking a folder full of Workbooks and seeing if there is a corresponding text file in another folder.
I know how to check through a folder for the Workbooks, and I know how to check to see if a file exists but I just can't get them to work together :-/
What my code attempts to do is find a Workbook name and then take a part of that Workbook name and use it to look for a text file.
Going back to basics, this is the code that I came up with originally based on what I already knew;
Code:
Sub CheckSheets()
PAfilePath = "G:\Pricing Sheets\"
SubfilePath = "G:\Pricing Sheets\Price Files\"
PriceAnalyser = Dir$(PAfilePath & "*.xlsm")
Do While PriceAnalyser <> ""
PMName = Left(Mid(PriceAnalyser, InStr(PriceAnalyser, " - ") + 3, Len(PriceAnalyser)), Len(Mid(PriceAnalyser, InStr(PriceAnalyser, " - ") + 3, Len(PriceAnalyser))) - 5)
If Dir(SubfilePath & PMName & ".txt") = "" Then '' Doesn't exist
MsgBox PMName
End If
PriceAnalyser = Dir$
Loop
End Sub
I'm getting the error "Invalid procedure call or argument" on;
Code:
PriceAnalyser = Dir$
After it's done the first loop.
I've tried various things to get it to work but all have failed, I've been working on the premise that because I use 'Dir' twice then something is going wrong.
The first Workbook gets named as I'd expect; in the test environment I've set up then the text file for this workbook doesn't exist and the Message Box gives me the name but then I get the error after that.
If I remove the IF statement then it loops through all of the Workbooks get named in my Message Box.
Any help would be much appreciated
Thanks for taking the time to look at this.