Search code examples
excelexcel-2007vba

Excel Vba not opening correct workbooks?


My excel code was able to iterate through every workbook in a specified folder, although it does so in an eternal loop. (Which i stop using the keyboard interrupt)

Vba based off this: http://www.ozgrid.com/VBA/2007-filesearch-alternative.htm

Now, after switching PCs, the code has gone haywire. The vba is still the same but instead of opening workbooks in the specified folder, its opening workbooks in the folder one folder before it.

E.g Vba is in S:\Excel\Test It will open books in S:\Excel Instead of a specified location in C. Drive S is a networked drive

Not only that, while it used to iterate through EVERY file, it now just keeps resetting and opening the first file again and again

Using Excel 2007


Solution

  • Guys the answer is simple. Because im using a networked drive, one should refer to the drive on which the workbook is stored. Adding one line to the top above ChDir solves this

    ChDrive (Left (ThisWorkbook.Path, 2))

    Im also glad to report that this question did not require me posting my code as well.