2
行“输入#1,数字(行,列)”给我一个运行时错误9.任何想法?代码中的评论解释了应该发生的事情。视觉基础Excel txt输入文件
Sub InputImage()
'brings a text file to the workbook
Dim Row As Long, Column As Long, Nrow As Long, Ncolumn As Long
Call MsgBox("Navigate to a folder that contains the file image.txt in the 00_18 folder")
' The next statement will open a dialogue box that will let
' the user navigate to any folder on their system
Call Application.GetOpenFilename
Open "image.txt" For Input As #1
Dim Buffer As String
Line Input #1, Buffer 'read a whole line of characters from
'file #1 into the string variable buffer
Line Input #1, Buffer
Input #1, Buffer, Nrow
Input #1, Buffer, Ncolumn
Dim Numbers(1 To 4, 1 To 4) As Long
For Row = 1 To Nrow
For Column = 1 To Ncolumn
Input #1, Numbers(Row, Column)
Next Column
Next Row
Close #1
End Sub
发生错误时行和列的值是什么? – 2013-03-13 06:11:41
错误9下标超出范围意味着您的数组和您的文本文件中的数据不是好友:-)。如果您可以将要从文件image.txt读取的数据发布到数组Numbers,这将会很有帮助。 – dee 2013-03-13 07:12:15
你知道你可以阅读你的文本文件作为查询使用ADO如果它的分隔 - 看看[MSDN脚本诊所:很多ADO关于文本文件](http://msdn.microsoft.com/en-us/library/ms974559。 aspx) – 2013-03-13 09:19:06