2

I am using dir() function in Excel vba programming with filter as ".xls".

But I have input files with the extension both ".xls" and ".xlsx" which have to be picked up for the process.

In many systems the macro picks the ".xlsx" and ".xls" files even though the filter specified as ".xls" in the macro.

But in some systems it picks up only "xls" files and not ".xlsx" files.

Any specific reason for this?

Community
  • 1
  • 1
Ramprakash
  • 21
  • 1
  • 2

1 Answers1

4

This doesn't answer the question "why does this happen", but it is a workaround:

Use ".xls?" or ".xls*" as your Dir filter:

MyFile = Dir("*.xls?")

or

MyFile = Dir("*.xls*")
Jean-François Corbett
  • 37,420
  • 30
  • 139
  • 188
  • I think also his missing "*." in the file spec is not doing any good. I will bet that the difference between systems is a FAT32/NTFS difference in treatment of this somewhat wonky filename. – Chris Rae Jun 30 '11 at 18:47