I need to create an extract process for an application. The end user insists that the file be displayed in Excel.
I wrote code to create a .txt file easily enough. However I get the following error when I try to open the file.
An unhandled exception of type 'System.Runtime.InteropServices.SafeArrayTypeMismatchException' occurred in mscorlib.dll
Additional information: Specified array was not of the expected type.
Here is the code:
Dim oXL As Object
Dim intLen As Integer
Dim strTemp As String
Dim varTempArray() As VariantType = {0, 0}
Dim varJaggedArray(9)() As VariantType ' array of arrays
Dim i As Integer
For i = 0 To 9
varTempArray(0) = i + 1
varTempArray(1) = 2
varJaggedArray(i) = varTempArray
Next
' Start Excel and get Application object.
oXL = CreateObject("Excel.Application")
oXL.Visible = True
'open workbook
oXL.Workbooks.OpenText(strF, StartRow:=1, _
DataType:=Excel.XlTextParsingType.xlDelimited, _
TextQualifier:=Excel.XlTextQualifier.xlTextQualifierSingleQuote, TAB:=True, FieldInfo:=varJaggedArray)
If I remove FieldInfo:=varJaggedArray from the OpenText statement the code works fine and opens the document. The problem is that I need the columns formatted as text. Some of the data is numeric in nature with leading zeroes and I need to maintain the leading zeroes.
Any suggestions?? Thanks.
I wrote code to create a .txt file easily enough. However I get the following error when I try to open the file.
An unhandled exception of type 'System.Runtime.InteropServices.SafeArrayTypeMismatchException' occurred in mscorlib.dll
Additional information: Specified array was not of the expected type.
Here is the code:
Dim oXL As Object
Dim intLen As Integer
Dim strTemp As String
Dim varTempArray() As VariantType = {0, 0}
Dim varJaggedArray(9)() As VariantType ' array of arrays
Dim i As Integer
For i = 0 To 9
varTempArray(0) = i + 1
varTempArray(1) = 2
varJaggedArray(i) = varTempArray
Next
' Start Excel and get Application object.
oXL = CreateObject("Excel.Application")
oXL.Visible = True
'open workbook
oXL.Workbooks.OpenText(strF, StartRow:=1, _
DataType:=Excel.XlTextParsingType.xlDelimited, _
TextQualifier:=Excel.XlTextQualifier.xlTextQualifierSingleQuote, TAB:=True, FieldInfo:=varJaggedArray)
If I remove FieldInfo:=varJaggedArray from the OpenText statement the code works fine and opens the document. The problem is that I need the columns formatted as text. Some of the data is numeric in nature with leading zeroes and I need to maintain the leading zeroes.
Any suggestions?? Thanks.