当我已经使用Workbooks.OpenText打开它时closures文本文件

我在这个论坛是新的,我想分享我的智慧,你把我的你的。

我有足够的Excelmacros的经验,但这个问题我找不到解决scheme。

我打开一个文本文件与Workbooks.OpenText在Excel中工作。

Workbooks.OpenText Filename:=myfile, DataType:=xlDelimited, Origin:=xlWindows, Other:=True, OtherChar:=","

但是当我结束时,我不能。 我尝试下一个指示:

  • 工作簿(MYFILE).Close
  • ActiveWorkbook.Close

myfile = "path\file.txt"

当我使用这个指令时,Excel表示我不能使用它。 我只需要获取这些文本文件的一些信息,并closures它没有保存。

有人可以帮我吗?

这也适用于我

 Sub Sample() Dim myfile As String myfile = "C:\Delete Me.txt" Workbooks.OpenText fileName:=myfile, _ DataType:=xlDelimited, _ Origin:=xlWindows, _ Other:=True, _ OtherChar:="," myfile = GetFilenameFromPath(myfile) Workbooks(myfile).Close End Sub Public Function GetFilenameFromPath(ByVal strPath As String) As String If Right$(strPath, 1) <> "\" And Len(strPath) > 0 Then GetFilenameFromPath = _ GetFilenameFromPath(Left$(strPath, Len(strPath) - 1)) + Right$(strPath, 1) End If End Function