DsSet 为一个标签,用于存放路径
TSPB1 为一个进度条
ToolInstruc 为一个标签,用于显示数字进度
RadioButton10 直接标记
'*******************以下为按钮代码****************************************************
Dim xFina As String
xFina = "No Set"
If Microsoft.VisualBasic.Left(Microsoft.VisualBasic.Right(DsSet.Text, 4), 1) = "." Then
xFina = Microsoft.VisualBasic.Right(DsSet.Text, 4)
End If
If Microsoft.VisualBasic.Left(Microsoft.VisualBasic.Right(DsSet.Text, 5), 1) = "." Then
xFina = Microsoft.VisualBasic.Left(Microsoft.VisualBasic.Right(DsSet.Text, 5), 4)
End If
If xFina <> ".xls" Then
If xFina <> ".XLS" Then
MsgBox("请先设置数据源!", MsgBoxStyle.Exclamation, "提示")
Exit Sub
End If
End If
Dim DataSPath As String
DataSPath = Microsoft.VisualBasic.Right(DsSet.Text, Len(DsSet.Text) - 6)
Dim ExlApp = CreateObject("Excel.Application")
Dim xlbook = ExlApp.Workbooks
Dim xlbk = ExlApp.workbooks.Open(DataSPath)
Dim MubPath As String
MubPath = Microsoft.VisualBasic.Right(ToolStrpStat2.Text, Len(ToolStrpStat2.Text) - 5)
Dim MuBk = ExlApp.workbooks.open(MubPath)
ExlApp.application.displayalerts = False
MuBk.sheets(1).copy(after:=xlbk.sheets(1))
ExlApp.application.displayalerts = True
MuBk.close(True)
Dim St1 = xlbk.worksheets(1)
Dim St2 = xlbk.worksheets(2)
St2.select()
Dim RngNu2 = ExlApp.ActiveSheet.UsedRange.Rows.Count
TSPB1.Visible = True
TSPB1.Value = 0
TSPB1.Minimum = 0
TSPB1.Maximum = RngNu2
ExlApp.Visible = False
Dim i As Integer
For i = 2 To RngNu2
TSPB1.Value = i
ToolInstruc.Text = i & "/" & RngNu2 & " ←→ " & ExlApp.round(i / RngNu2 * 100, 2) & "%"
Dim FndStr, ReplStr As String
If Microsoft.VisualBasic.Left(St2.cells(i, 4).value, 5) = "错误类型1" Then
FndStr = St2.cells(i, 2).value
ReplStr = St2.cells(i, 3).value
Dim xFnd = St1.range("F:F").find(FndStr)
If Not xFnd Is Nothing Then
Dim Cnub As Integer
Cnub = Microsoft.VisualBasic.Right(xFnd.Address, Len(xFnd.Address) - 3)
Dim xRepStr As String
xRepStr = St2.cells(Cnub, 4).value
If RadioButton10.Checked = False Then
If Len(St1.cells(Cnub, 7).value) = Len(ReplStr) Then
St1.cells(Cnub, 9) = "←*→" & ReplStr
St2.cells(i, 9) = "Find"
St1.cells(Cnub, 7).value = ""
Else
If Microsoft.VisualBasic.Right(St1.cells(Cnub, 7).value, Len(ReplStr)) = ReplStr Then
St1.cells(Cnub, 9) = "→" & ReplStr
St2.cells(i, 9) = "Find"
St1.cells(Cnub, 7).value = "'" & Microsoft.VisualBasic.Left(St1.cells(Cnub, 7).value, Len(St1.cells(Cnub, 7).value) - Len(ReplStr) - 1)
Else
If Microsoft.VisualBasic.Left(St1.cells(Cnub, 7).value, Len(ReplStr)) = ReplStr Then
St1.cells(Cnub, 9) = "←" & ReplStr
St2.cells(i, 9) = "Find"
St1.cells(Cnub, 7).value = "'" & Microsoft.VisualBasic.Right(St1.cells(Cnub, 7).value, Len(St1.cells(Cnub, 7).value) - Len(ReplStr) - 1)
Else
ExlApp.application.displayalerts = False
St1.range("G:G").Replace("/" & ReplStr, "")
ExlApp.application.displayalerts = True
St1.cells(Cnub, 9) = "←→" & ReplStr
End If
End If
End If
End If
If RadioButton10.Checked = True Then
St2.cells(i, 9) = "Find"
St1.cells(Cnub, 9) = "←→" & ReplStr
End If
If RadioButton11.Checked = True Then
If Len(xRepStr) > 0 Then
Dim FilStr As String
FilStr = ""
Dim RepStr1 = Replace(xRepStr, FndStr, "")
Dim RepStr2 = Replace(RepStr1, "//", "/")
If Microsoft.VisualBasic.Left(RepStr2, 1) = "/" Then
FilStr = Microsoft.VisualBasic.Right(RepStr2, Len(RepStr2) - 1)
End If
If Microsoft.VisualBasic.Right(RepStr2, 1) = "/" Then
FilStr = Microsoft.VisualBasic.Left(RepStr2, Len(RepStr2) - 1)
End If
St2.cells(Cnub, 4).value = "'" & FilStr
End If
End If
End If
End If
Next
ExlApp.activeworkbook.close(True)
ExlApp.quit()
xlbook = Nothing
ExlApp = Nothing
TSPB1.Visible = False
ToolInstruc.Text = "已完成!"
MsgBox("OK", MsgBoxStyle.Exclamation, "Tudy")
评论0