I need to use excel with the xls extension, but some macros don't work that work on xlsm.

Private Sub Worksheet_Change(ByVal Target As Range) Dim objCell As Range If Target.Row = 1 Then Exit Sub If Not Application.Intersect(Range("A:I"), Target) Is Nothing Then Application.EnableEvents = False For Each objCell In Target With objCell If Len(.Value) > 0 Then Select Case .Column Case 1, 2 If TypeName(.Value) = "String" Then .Value = Left(.Value, 10) Else .Value = "" End If Case 4, 5 If .Value <> 0 And .Value <> 1 Then .Value = "" Case 6, 7 .Value = Replace(.Value, ";", "") Case 8, 9 If Not IsNumeric(.Value) Then .ClearContents End Select End If End With Next objCell Application.EnableEvents = True End If End Sub 

A macro like this in xls does nothing. The xlsm works.

Question: how can i use macros in xls?

  • describe the question in more detail, give an example of a macro, if you want to get the correct answer. - Denis
  • And why not use xlsm? - T.Zagidullin
  • Because the data is entered into the database using file import, where there is support for xls and xlsx formats, but not xlsm. I want to put macros on the files to check the data - then write to the database. - Kamil Askerov
  • forum.msexcel.ru/index.php/topic,11513.0.html The link was checked, the code in Excel-2003 works. - vikttur
  • Data cleared - after that it worked. Thanks you. vikttur - Kamil Askerov

1 answer 1

The code shown by the author in Excel 2003 works.

Possible reasons for the inoperability in Exel-2003 macros created in later versions.

Using the methods that appeared later will cause an error when applied in Excel 2003 . For example, there were cases of broken sorting.

The error may be if the code is written by the macrorecoder and the record after it is not optimized. For example: cell formatting can be written in one line; The macrorecoder will display about 10 parameters, among which are incompatible with the old version.

In Excel-2003 2 ^ 16 lines, in Excel-2010 - 2 ^ 20. If the code contains a reference to a cell or a range below the string 65536 - an error.

In Excel 2010, you can use API functions for the 64-bit version, Excel 2003 does not know how.

Probably, problem code uses libraries that are not / are not connected.

'---------------

Somehow automatically establish a friendship of new version macros and Excel-2003 will fail. You need to view the code and remove the flaws.

  • I understand the xls extension was used in 2003 excel? There are no restrictions that are described in the answer there is not used. T. o. everything should work correctly in 2003. - Kamil Askerov
  • Hooray it worked. Strange cleared all the data after that. Thanks to all. Home thanks to vikttur - Kamil Askerov