我想使用宏从用户表单中复制代码,但是找不到任何方法,请帮忙。
答案 0 :(得分:1)
此函数将获取用户窗体,代码模块或类模块的文本。您将需要@SHK提到的Microsoft VBA可扩展性5.5参考。
Function getCodeText(wb As Workbook, moduleName As String) As String
Dim myCode As VBIDE.CodeModule
Set myCode = wb.VBProject.VBComponents.Item(moduleName).CodeModule
getCodeText = myCode.Lines(1, myCode.CountOfLines)
End Function
Sub testCall()
MsgBox getCodeText(Workbooks("MyWorkbook.xlsm"), "MyUserformName")
End Sub