After an upgrade to Excel 2010 (from 2003), a script used for standardizing data from Access import has stopped working. It returns an error: "Run-time error '1004': Method 'OpenText' of object 'Workbooks' failed".
Prior to the OpenText portion, the macro searches a folder for the most recent file by DateCreated and then returns the filename and path.
The relevant code is:
Workbooks.OpenText FileName:=myDir & "\" & strFilename, _
Origin:=-535, StartRow:=1, DataType:=xlDelimited, TextQualifier:= _
xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, Semicolon:=False _
, Comma:=True, Space:=False, Other:=False, FieldInfo:=Array(Array(1, 2), _
Array(2, 2), Array(3, 2), Array(4, 2), Array(5, 2), Array(6, 2), Array(7, 2), Array(8, 2), _
Array(9, 2), Array(10, 2), Array(11, 2), Array(12, 2), Array(13, 2), Array(14, 2), Array(15 _
, 2), Array(16, 3), Array(17, 3), Array(18, 3), Array(19, 3), Array(20, 2), Array(21, 2), _
Array(22, 1), Array(23, 2), Array(24, 2), Array(25, 3), Array(26, 2), Array(27, 2), Array( _
28, 2)), TrailingMinusNumbers:=True
Any ideas what may be hanging Excel 2010 up?
The file is still a .xls file, and is running in Compatibility Mode, which I have not had issues with in any other macro yet.
UPDATED after recording new macro and comparing w/ old:
The new macro one difference, the Origin argument.
In the old macro:
Origin:=-535
The new macro:
Origin:=65001
Reading up on Origin, this appears to be the source of the file to be imported, and it can be omitted.
What importance would Origin have on the import? The DataType is already specified. Does Origin control the encoding?
Removing Origin from the original Macro, the same error is returned. Changing the Origin value to 65001 still returns the same error.