其他分享
首页 > 其他分享> > 动态执行文本vba代码

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

标签:ThisWorkbook,vba,End,Sub,代码,vbComp,VBComponents,StringExecute,文本
来源: https://www.cnblogs.com/jjj250/p/11597976.html