|
vbscript源代码:- ' the code below force script runs on cscript instead of wscript
- Function IsCScript()
- ' Check whethe CScript.exe is the host.
- If (InStr(UCase(WScript.FullName), "CSCRIPT") <> 0) Then
- IsCScript = True
- Else
- IsCScript = False
- End If
- End Function
- Sub ForceInCScript()
- Dim WshShell
- Set WshShell = WScript.CreateObject("WScript.Shell")
-
- If (Not IsCScript()) Then
- WshShell.Run "CScript.exe " & """" & WScript.ScriptFullName & """"
- WScript.Quit ' Terminate script.
- End If
- End Sub
- ForceInCScript
- ' This code try to connect WPS ET,if failed then connect to Excel
- Dim ExcelApp
- On Error Resume Next
- ' try to connect to et or excel
- Set ExcelApp = GetObject(, "Excel.Application")
- If ExcelApp Is Nothing Then
- Set ExcelApp = GetObject(, "KET.Application")
- If ExcelApp Is Nothing Then
- Set ExcelApp = GetObject(, "ET.Application")
- If ExcelApp Is Nothing Then
- MsgBox "Run Excel or Kingsoft ET first.", vbInformation, "Information"
- WScript.Quit
- End If
- End If
- End If
- On Error Goto 0
- Dim Workbook, ActiveSheet
- Set Workbook = ExcelApp.ActiveWorkbook
- Set ActiveSheet = Workbook.ActiveSheet
- Dim MaxRow, MaxCol
- MaxRow = ActiveSheet.UsedRange.Row + ActiveSheet.UsedRange.Rows.Count-1
- MaxCol = ActiveSheet.UsedRange.Column + ActiveSheet.UsedRange.Columns.Count-1
- If ExcelApp.ActiveWorkbook Is Nothing Then
- MsgBox "No documents was opened."
- WScript.Quit
- End If
- i=2
- Do While i<=MaxRow
- If (0<>InStr("BCDEFG",Left(Trim(ActiveSheet.Cells(i,4).value),1))) _
- And (ActiveSheet.cells(i, 3).value="") Then
- ActiveSheet.Cells(i-1,4).Value = ActiveSheet.Cells(i-1,4).value & ";" & ActiveSheet.Cells(i,4).Value
- ActiveSheet.Cells(i-1,4).Select
- ActiveSheet.Rows(i).Delete
- MaxRow=MaxRow-1
- i=i-1
- wscript.echo "处理数据" & Round(i/MaxRow*100, 2) & "%, 第" & i & "/" & MaxRow & "行"
- End If
- i=i+1
- Loop
复制代码 |
|