如何捕捉错误“文件未完全加载”

我有一个打开文本文件的代码。 它包含的行数超过了Excel的限制。 当手动打开它,有一个提示说:“文件未被完全加载”,但在macros时,我没有看到提示。

我想要做的就是抓住那个错误。 即使当我的macros的显示警报启用,仍然没有错误被捕获。

On Error Goto catch_err ...open text file here On Error Goto 0 catch_err: Msgbox err.description 

这是我的代码的结构。

为什么不在每次打到1M行时将文件stream入并移到下一个选项卡?

我把它们一起扔给你,请原谅那里的Citrix线(我需要它进行testing,如果你在这个环境中,就把它留下)。

 Sub BigFile() Dim myFile As String, textline As String, X As Long 'myFile = "\\Client\C$\Temp\YourBigFile.txt" 'Silly Citrix syntax myFile = "C:\Temp\YourBigFile.txt" 'Normal syntax Open myFile For Input As #1 Do Until EOF(1) X = X + 1 If X = 1000000 + 1 Then Sheets.Add X = 1 End If Line Input #1, textline Range("A" & X).Formula = textline Loop Close #1 End Sub 

这样你不需要testing错误,因为不会有错误。