错误'1004'应用程序定义或对象定义的错误发生 [英] Error '1004' Application-defined or Object-defined Error Occured

查看:94
本文介绍了错误'1004'应用程序定义或对象定义的错误发生的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Sub ReadLineByLine()
     
    Dim strLine As String
    Dim oFS As Object
    Dim oTS As Object
    Dim lineNumber As Integer
    
    Set oFS = CreateObject("Scripting.FileSystemObject")
     
    Set oTS = oFS.OpenTextFile("C:\SYDNEY ERS_121713.txt")
     
    Do While oTS.AtEndOfStream = False
         
        strLine = oTS.Readline
        
        Dim Item1 As String
                
        Dim RowItm As Long
                
        RowItm = Range("A65536").End(xlUp).Row + 1
        ColItm = "A" & RowItm
        
        Item1 = Mid(strLine, 3, 23)
        Range(ColItem).Value = Item1 ' Error Occurs here!
        
    Loop
     
     
    oTS.Close
    Set oTS = Nothing
    Set oFS = Nothing
     
End Sub





我不知道为什么会出现这种错误。我已经调试了很多次了。救命。 :(



I do not know why that error occurs. I have debugged it many times already. Help. :(

推荐答案

看看 MS Excel OpenText [ ^ ]方法。它将文本文件作为新工作簿加载和解析,其中包含一个包含已解析文本文件数据的工作表。



我建议你录制宏;)
Have a look at MS Excel OpenText[^] method. It loads and parses a text file as a new workbook with a single sheet that contains the parsed text-file data.

I would suggest you to record macro ;)


这篇关于错误'1004'应用程序定义或对象定义的错误发生的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆