简体   繁体   中英

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.

Eg 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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM