动态执行文本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

转载于:https://www.cnblogs.com/jjj250/p/11597976.html

你可能感兴趣的:(动态执行文本vba代码)