动态执行文本vba代码

动态执行文本vba代码

Public Sub StringExecute(s As String)

Dim vbComp As Object

Set vbComp = ThisWorkbook.VBProject.VBComponents.Add(1)

vbComp.Name = "aaa"

vbComp.CodeModule.AddFromString "Sub foo" & vbCrLf & s & vbCrLf & "End Sub"

Application.Run vbComp.Name & ".foo"

ThisWorkbook.VBProject.VBComponents.Remove vbComp

End Sub

Sub Testing()

StringExecute "MsgBox" & """" & "Job Done!" & """"

End Sub

上一篇:数据结构C++实现代码-顺序表


下一篇:C#动态执行代码