LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 24
Default Modify Macro Code Depending on Excel Version

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


 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Modify a Macro Carl Excel Worksheet Functions 1 October 28th 06 10:32 AM
Help Required!!! Macro to load data from version 1 to version 2 [email protected] Excel Worksheet Functions 0 August 23rd 06 07:27 AM
How to modify a copy macro EAHRENS Excel Worksheet Functions 4 March 13th 06 06:58 PM
Recover earlier version of excel sheet after new version saved? stephanie38 Excel Discussion (Misc queries) 3 June 17th 05 03:52 AM
How do I modify a row depending upon what a cell value is? Brett Patterson Excel Worksheet Functions 5 November 6th 04 04:29 AM


All times are GMT +1. The time now is 11:51 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"