|

楼主 |
发表于 2008-11-20 09:22
|
显示全部楼层
Public yunx
Public yunxii As Dictionary
Function yx(a)
On Error GoTo ren
运行 = "运行"
yunxi = "Sub xi()" & Chr(10)
arr = a
For i = 1 To UBound(arr)
If arr(i, 1) Like "range*" Or arr(i, 1) Like "Range*" Then arr(i, 1) = "ActiveSheet." & arr(i, 1)
If arr(i, 1) <> "" Then yunxi = yunxi & arr(i, 1) & Chr(10)
Next i
yunxi = yunxi & "End Sub" & Chr(10)
s = yunxii(yunxi)
Set yunx = New csss
Set yunx.sht = ActiveSheet
Exit Function
ren:
If a Like "call*" Or a Like "Call*" Then
Application.Run Mid(a, 5, Len(a))
Exit Function
End If
yunxi = "sub xi()" & Chr(10) & a & Chr(10) & "end sub"
s = yunxii(yunxi)
Set yunx = New csss
Set yunx.sht = ActiveSheet
End Function
Public WithEvents sht As Worksheet
Private Sub sht_Change(ByVal Target As Range)
On Error GoTo ren
Set yunx.sht = Nothing
Set yunx = Nothing
Set s = CreateObject("MSScriptControl.ScriptControl")
s.Language = "VBScript"
s.AddObject "ActiveWorkbook", ActiveWorkbook
s.AddObject "Application", Application
s.AddObject "Activesheet", ActiveSheet
s.AddObject "sheets", Sheets
s.AddObject "cells", Cells
arr = yunxii.Keys
For i = 0 To UBound(arr)
s.addcode arr(i)
s.Run "xi"
Next i
s.Reset
yunxii.RemoveAll
ren:
End Sub
我没有调试,你参考以上代码.不过这种方法很容易引起连锁反应.小心再小心 |
|