Hey guys,
I am struggling with this issue for a long time, please help.
I have this code that coverts excel sheets to text file. This was working till my system was upgraded to office 2003.
Here is the code:
Private Function SaveXLasText(ByVal XLSourceFilename As String, ByVal TempTextFilename As String) As Array
Dim i As Integer
Dim txtFileName() As String
Dim XLApp As New Microsoft.Office.Interop.Excel.Application
Dim TextFormat As Microsoft.Office.Interop.Excel.XlFileFormat = Microsoft.Office.Interop.Excel.XlFileFormat.xlTextWindows
Try
'XLApp = New Excel.Application
Dim ws As Microsoft.Office.Interop.Excel.Worksheet
''Hide Excel
XLApp.Visible = False
''Open an Excel workbook
XLApp.Workbooks.Open(XLSourceFilename)
''Turn off annoying messageboxes
XLApp.AskToUpdateLinks = False
XLApp.DisplayAlerts = False
''Save the file as text
i = 0
ReDim txtFileName(i)
txtFileName(i) = "NULL" 'Since VB.NET arry starts from Zero, so defaulting zero location to NULL
For Each ws In XLApp.Worksheets
i = i + 1
ReDim Preserve txtFileName(i)
txtFileName(i) = TempTextFilename & i & ".txt"
ws.SaveAs(FileName:=txtFileName(i), FileFormat:=TextFormat, CreateBackup:=False)
Next
Catch ex As Exception
Console.WriteLine(ex.Message)
Finally
'Close the workbook
XLApp.ActiveWorkbook.Close(Savechanges:=False)
''Turn annoying messages back on
XLApp.DisplayAlerts = True
''Quit Excel
XLApp.Quit()
XLApp.kill()
''Kill the variable
XLApp = Nothing
End Try
Code works till this point:
ws.SaveAs(FileName:=txtFileName(i), FileFormat:=TextFormat, CreateBackup:=False)
This is the error message I get:
Message "The file could not be accessed. Try one of the following:
• Make sure the specified folder exists.
• Make sure the folder that contains the file is not read-only.
• Make sure the file name does not contain any of the following characters: < > ? [ ] : | or *
• Make sure the file/path name doesn't contain more than 218 characters." String
Please help:
Thanks
I am struggling with this issue for a long time, please help.
I have this code that coverts excel sheets to text file. This was working till my system was upgraded to office 2003.
Here is the code:
Private Function SaveXLasText(ByVal XLSourceFilename As String, ByVal TempTextFilename As String) As Array
Dim i As Integer
Dim txtFileName() As String
Dim XLApp As New Microsoft.Office.Interop.Excel.Application
Dim TextFormat As Microsoft.Office.Interop.Excel.XlFileFormat = Microsoft.Office.Interop.Excel.XlFileFormat.xlTextWindows
Try
'XLApp = New Excel.Application
Dim ws As Microsoft.Office.Interop.Excel.Worksheet
''Hide Excel
XLApp.Visible = False
''Open an Excel workbook
XLApp.Workbooks.Open(XLSourceFilename)
''Turn off annoying messageboxes
XLApp.AskToUpdateLinks = False
XLApp.DisplayAlerts = False
''Save the file as text
i = 0
ReDim txtFileName(i)
txtFileName(i) = "NULL" 'Since VB.NET arry starts from Zero, so defaulting zero location to NULL
For Each ws In XLApp.Worksheets
i = i + 1
ReDim Preserve txtFileName(i)
txtFileName(i) = TempTextFilename & i & ".txt"
ws.SaveAs(FileName:=txtFileName(i), FileFormat:=TextFormat, CreateBackup:=False)
Next
Catch ex As Exception
Console.WriteLine(ex.Message)
Finally
'Close the workbook
XLApp.ActiveWorkbook.Close(Savechanges:=False)
''Turn annoying messages back on
XLApp.DisplayAlerts = True
''Quit Excel
XLApp.Quit()
XLApp.kill()
''Kill the variable
XLApp = Nothing
End Try
Code works till this point:
ws.SaveAs(FileName:=txtFileName(i), FileFormat:=TextFormat, CreateBackup:=False)
This is the error message I get:
Message "The file could not be accessed. Try one of the following:
• Make sure the specified folder exists.
• Make sure the folder that contains the file is not read-only.
• Make sure the file name does not contain any of the following characters: < > ? [ ] : | or *
• Make sure the file/path name doesn't contain more than 218 characters." String
Please help:
Thanks