View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.misc
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default Modify Macro Code Depending on Excel Version

If your code works ok in xl97 without that option, why do you need it in xl2003?

If you decide you don't need it, just remove that parameter.

John Taylor wrote:

G'day to all,

I have an Excel 97 macro which imports csv data, including dates in
dd/mm/yyyy format, and would like to be able to use it with both Excel 97
and Excel 2003.

When I ran it in XL2003 some dates were imported in the wrong format, and on
checking the MS Knowledgebase (911759) I found that it's a known problem.

The workaround is to add 'Local:=True' to the import code. So my code for
XL2003 now looks like this:

Workbooks.OpenText FileName:="C:\temp\" & MyStockCSV, Origin:=xlWindows, _
StartRow:=1, DataType:=xlDelimited, TextQualifier:=xlDoubleQuote,
Comma:=True, _
Space:=False, Other:=False, FieldInfo:=Array(Array(1, 1), Array(2, 5), _
Array(3, 1), Array(4, 1), Array(5, 1), Array(6, 1)), Local:=True

Works fine in XL2003, but XL97 doesn't like the 'local', and gives a
"Compile error: Named argument not found" message.

I thought I could overcome it by checking for the version, but the following
code that I tried doesn't work. Before it actually runs I get the same
message as above.

If Val(Left(Application.Version, 3)) = 8# Then ' Excel 97 is running
Workbooks.OpenText FileName:="C:\temp\" & MyStockCSV, Origin:=xlWindows, _
StartRow:=1, DataType:=xlDelimited, TextQualifier:=xlDoubleQuote,
Comma:=True, _
Space:=False, Other:=False, FieldInfo:=Array(Array(1, 1), Array(2, 5), _
Array(3, 1), Array(4, 1), Array(5, 1), Array(6, 1))
Else
Workbooks.OpenText FileName:="C:\temp\" & MyStockCSV, Origin:=xlWindows, _
StartRow:=1, DataType:=xlDelimited, TextQualifier:=xlDoubleQuote,
Comma:=True, _
Space:=False, Other:=False, FieldInfo:=Array(Array(1, 1), Array(2, 5), _
Array(3, 1), Array(4, 1), Array(5, 1), Array(6, 1)), Local:=True
End If

I expected that if the macro was being used in XL97 then the first
Workbooks.Open line would run, and then exit the If construct. However,
that doesn't appear to be the case.

Could someone suggest how the code can be modified so that it will run in
both XL97 and XL2003.

Regards,

John


--

Dave Peterson