我制作了一个脚本,允许用户使用 shell 浏览器打开文件,一旦选择,系统会提示他们输入他们想要将 .CSV 文件拆分为较小文件的时间间隔。
出现的问题是,一旦我使用浏览器选择文件,我会收到代码 80004005 的未指定错误,它出现在第 15 行字符 1 上,我不知道如何解决这个问题。
任何帮助将非常感激!
Option Explicit
Const ForReading = 1
Const ForWriting = 2
Dim objFSO, objInputFile, objOutputFile
Dim intLine, intFile
Dim strHeaders
Dim strInputFile, strOutputPrefix, strLine
Dim MyDate
Dim shell
Dim file
Set shell = CreateObject("Shell.Application")
Set file = shell.BrowseForFolder(0, "Choose a file:", &H4000)
BrowseForFile = file.self.Path
strInputFile = BrowseForFile
strOutputPrefix = objFSO.GetBaseName(strInputFile) & DatePart("yyyy", Now) & "-" & DatePart("m", Now) & "-" & DatePart("d", Now)
userSplit = InputBox("Enter when you want to split")
intFile = 1
intLine = 0
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objInputFile = objFSO.OpenTextFile(strInputFile, ForReading)
If (objInputFile.AtEndOfStream = True) Then
' The file is empty
WScript.Quit 1
End If
strHeaders = objInputFile.ReadLine
Do While (objInputFile.AtEndOfStream = False)
strLine = objInputFile.ReadLine
If (intLine <= 0) Then
Set objOutputFile = objFSO.CreateTextFile(strOutputPrefix & "_" & intFile & ".csv", True)
objOutputFile.WriteLine strHeaders
intLine = 1
End If
objOutputFile.WriteLine strLine
If (intLine >= userSplit) Then
objOutputFile.Close
Set objOutputFile = Nothing
intFile = intFile + 1
intLine = 0
Else
intLine = intLine + 1
End If
Loop