- Dim strPath
- Dim arr, arrLine, 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("C:\Users\admin\Desktop\test\d.xlsx")
- Set oSheet = oWorkBook.Sheets(1)
- arr = oSheet.UsedRange.Range("B1:C" & oSheet.UsedRange.Rows.Count)
- Set oSheet = Nothing
- oWorkBook.Close False
- Set oWorkBook = Nothing
- oExcel.Quit
-
- ReDim arrLine(UBound(arr, 1)-1)
- For a = 1 To UBound(arr, 1)
- arrLine(a-1) = arr(a, 2) & "," & arr(a,1)
- Next
-
- str = Join(arrLine, vbCrLf)
- Write strpath & ".txt" , Join(arrLine, vbCrLf)
-
-
- 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
复制代码
|