- Dim strPath
- Dim arr, brr, t
- If wscript.Arguments.Count = 0 Then
- MsgBox "拖拽Excel文件到本vbs文件", 0, "提示"
- End If
- For jb = 0 To wscript.Arguments.Count - 1
- strPath = wscript.Arguments(jb)
- MsgBox "将要导出" & strPath, vbOKCancel, "提示"
- Next
- Set oExcel = CreateObject("Excel.Application")
- Set oWorkBook = oExcel.Workbooks.Open(strPath)
- Set oSheet = oWorkBook.Sheets(1)
- arr = oSheet.UsedRange.Range("B1:C" & oSheet.UsedRange.Rows.Count)
- ReDim brr(UBound(arr, 1))
- For a = 0 To UBound(arr, 1)
- brr(a) = arr(a, 1)
- For b = 2 To UBound(arr, 2)
- brr(a) = arr(a, b) & "," & brr(a)
- 'brr(a) = brr(a) & "," & arr(a, b)
- Next
- Next
- Write strpath & ".txt" , Join(brr, vbCrLf)
- Set oSheet = Nothing
- oWorkBook.Close False
- Set oWorkBook = Nothing
- oExcel.Quit
- Sub Write(strName,str)
- Dim oFSO, oFile
- Set oFSO = CreateObject("Scripting.FileSystemObject")
- Set oFile = oFSO.OpenTextFile(strName, 2, True) '不存在则创建,强制覆盖
- oFile.Writeline str
- oFile.Close
- Set oFile = Nothing
- Set oFSO = Nothing
- End Sub
- reReplace(str ,"^" & vbcrlf,"")
- Function reReplace(str,patrn, replStr)
- Dim regEx, str1
- Set regEx = New RegExp
- regEx.Pattern = patrn
- regEx.IgnoreCase = True
- regEx.Global = false
- reReplace = regEx.Replace(str, replStr)
- End Function
复制代码
|