|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
- Sub opiona2() '//每个Sheet中写入代码
- '--------------要写入的代码----------------------------------------------------
- strProc = " Private Sub Worksheet_Change(ByVal Target As Range)"
- strProc = strProc & vbCrLf & " On Error Resume Next"
- strProc = strProc & vbCrLf & " If Target.Column = 3 Then"
- strProc = strProc & vbCrLf & " If InStr(Target.Value, " & Chr(34) & " " & Chr(34) & ") > 0 Then"
-
- strProc = strProc & vbCrLf & " MsgBox " & Chr(34) & "表中“AID”列的单元格数据存在空格,将自动给你删除空格" & Chr(34) & ", vbintformatiom, " & Chr(34) & "温馨提示" & Chr(34)
- strProc = strProc & vbCrLf & " Target.Value = Replace(Target.Value, " & Chr(34) & " " & Chr(34) & ", " & Chr(34) & "" & Chr(34) & ")"
- strProc = strProc & vbCrLf & " End If"
- strProc = strProc & vbCrLf & " End If"
- strProc = strProc & vbCrLf & "end sub "
- '-----------查找这个名称-------------------------------------
- For Each mk In ThisWorkbook.VBProject.VBComponents
- If InStr(mk.Name, "Sheet") > 0 Then
- ' MsgBox mk.Name
- 'mk.VBProject.VBComponents.Remove mk '//删除这个模块
- If mk.Name <> "ThisWorkbook" Or mk.Name <> "Sheet1" Then
- mk.CodeModule.AddFromString strProc '//插入代码
- End If
- End If
- Next
- End Sub
- Sub DelCodes() '//删除全部代码
- For Each mk In ThisWorkbook.VBProject.VBComponents
- If InStr(mk.Name, "Sheet") > 0 Then
- ' MsgBox mk.Name
- 'mk.VBProject.VBComponents.Remove mk '//删除这个模块
- If mk.Name <> "ThisWorkbook" Or mk.Name <> "Sheet1" Then
- With mk.CodeModule
- .DeleteLines 1, .CountOfLines '//删除全部代码
- End With
-
- End If
- End If
- Next
- End Sub
复制代码 |
|