【发布时间】:2019-09-17 23:16:11
【问题描述】:
知道为什么我在使用 Input 函数时不断收到运行时错误 62 Input past end of file 错误,并使用以下代码。帮助功能告诉我文件是二进制文件,我应该使用 LOF 或 Seek,但似乎都不起作用。在最近对我的计算机进行 Windows 和 Microsoft 更新之前,此代码运行良好。
Dim fldr As FileDialog
Dim sItem As String
Set fldr = Application.FileDialog(msoFileDialogFilePicker)
With fldr
.Filters.Clear
.Filters.Add "All files", "*.*"
.Title = "Select a CFG File to Convert fromatting from R2013 to 1991."
.AllowMultiSelect = False
.InitialFileName = ActiveWorkbook.Path 'Application.DefaultFilePath
If .Show <> -1 Then Exit Sub
sItem = .SelectedItems(1)
End With
set fldr = Nothing
Open sItem For Input As #1
dataArray = Split(Input(LOF(1), #1), vbLf)
Close #1
If Len(dataArray(2)) - Len(Replace(dataArray(2), ",", "")) = 9 Then
MsgBox "It appears the comtrade file format already conforms to the 1991 standard version." & vbNewLine & "" & vbNewLine & "Conversion was Aborted."
Exit Sub
End If
我正在尝试计算所选文件第 3 行中逗号的数量。
【问题讨论】:
-
不是问题,但“fromatting”应该是“formatting”;-)
-
FWIW 非常相似的文件阅读器代码以前被炸毁,请参阅 here - 我怀疑 Windows/Office 更新与它有什么关系。