1

I want my VBA code to execute only if the file format is xls. Is this correct? I'm doing this:

#If ActiveWorkbook.FileFormat = xlExcel5 Then
  //my code
Else
  //my code
#End if

I tested using Excel 2010 (xlsm file) and it worked fine. I already used PHPExcel library and this is why I chose the xlExcel5, because It's similar to the excel5 I had to choose if I wanted to work with the old excel versions (2003 or lower) while programming in Php.

Community
  • 1
  • 1
periback2
  • 1,459
  • 4
  • 19
  • 36
  • 1
    `ActiveWorkbook.FileFormat` will not give you the Excel Version. It will only give you the file format as you already mentioned. If you want to check the Excel Version on a particular pc then you have to use `If Val(Application.Version) < 12 Then` What exatcly are you trying to achieve? – Siddharth Rout Jan 30 '13 at 14:03
  • In fact what I want is really the file Format. I wanna know if I check it for xlExcel5, I can garantee it's a 2007 or lower version. Or can I have a xlExcel5 format generated in a 2010 excel? – periback2 Jan 30 '13 at 14:07
  • 3
    BTW the value of `xlExcel5` is 39. You can check that by typing `?xlExcel5` in the immediate window. Similarly the value of `FileFormat (xlExcel8)` for `xls` is 56. For more on fileformats, see this link http://msdn.microsoft.com/en-us/library/office/bb241279%28v=office.12%29.aspx – Siddharth Rout Jan 30 '13 at 14:10
  • I was typing when you posted the previous comment. let me check your previous comment – Siddharth Rout Jan 30 '13 at 14:13
  • 4
    The above link will answer your first question. For the 2nd, the answer is `It Depends` If you have the VBA convertor installed then yes you can have a `xlExcel5` format generated in a 2010 excel. If you do not have the convertor then the `xls` file will be saved without the VBA project if any. `xlExcel5` format is the `Excel 5.0/95 format` – Siddharth Rout Jan 30 '13 at 14:20
  • 1
    @SiddharthRout Please add your suggestions as an answer - I'd upvote and agree with the approach) – Peter L. Jan 30 '13 at 15:52

0 Answers0