VBA EXCEL:我可以将用户窗体的代码复制到txt文件吗?

时间:2018-11-09 13:27:59

标签: excel vba userform

我想使用宏从用户表单中复制代码,但是找不到任何方法,请帮忙。

1 个答案:

答案 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