Workbooks.OpenText错误“预期的函数或变量”

时间:2016-06-21 21:21:26

标签: excel-vba vba excel

为什么我的代码不起作用?它突出显示OpenText部分并声明“预期函数或变量”

Dim Indata As Excel.Workbook

Set Indata = Workbooks.OpenText(Filename:="C:\Users\thePunter\Desktop\Count_Types_062016.txt", DataType:=xlDelimited, Tab:=True)

2 个答案:

答案 0 :(得分:2)

您尝试在使用OpenText方法时设置工作簿变量,但OpenText不会返回工作簿引用。这样做

Dim Indata As Excel.Workbook
 Workbooks.OpenText(Filename:="C:\Users\thePunter\Desktop\Count_Types_062016.txt", DataType:=xlDelimited, Tab:=True)
Set Indata = ActiveWorkBook

答案 1 :(得分:0)

这应该解决它 - 尽管 -

'...
Dim Indata As Excel.Workbook
Call Workbooks.OpenText(Filename:="C:\Users\thePunter\Desktop\Count_Types_062016.txt", DataType:=xlDelimited, Tab:=True)
Set Indata = ActiveWorkbook
Indata.Close False
'...

但是,在使用csv和txt文件时,我发现EOF command.

非常有效