尝试在visual basic中打开.txt时出现COM异常

时间:2015-09-25 04:26:48

标签: vb.net excel vba excel-vba

我正在尝试从VB.net运行Excel宏,并且在尝试将.txt文件打开到Excel中的工作簿时遇到错误。这是我正在使用的代码:

Dim MASTERxlApp As New Application
Dim MASTERxlWorkbook As Workbook = MASTERxlApp.Workbooks.Add()
Dim MASTER As String = "C:\User\Documents\Sample.txt"
Dim MASTERfieldinfo As String = "{1, XlColumnDataType.xlGeneralFormat}"

MASTERxlApp.Workbooks.OpenText(
     Filename:=MASTER,
     Origin:=65001,
     StartRow:=1,
     DataType:=Excel.XlTextParsingType.xlDelimited,
     TextQualifier:=Excel.XlTextQualifier.xlTextQualifierDoubleQuote,
     ConsecutiveDelimiter:=False,
     Tab:=False,
     Semicolon:=False,
     Comma:=True,
     Space:=False,
     Other:=False,
     FieldInfo:={MASTERfieldinfo},
     TrailingMinusNumbers:=True)

调用Workbooks.Opentext()后抛出异常:

An unhandled exception of type
'System.Runtime.InteropServices.COMException'occurred in ConsoleApplication1.exe

Additional information: Exception from HRESULT: 0x800A03EC

我试图在Excel中更改Trust设置,并将VB2015中的活动平台设置为任何CPU。我正在导入Microsoft.Office.Interop.Excel。我使用的是Windows 10,VB 2015和Office Professional 2013。

任何想法都将不胜感激。

0 个答案:

没有答案