Excel VBA高级编程:对VBA编程环境(VBE)编程

2015-04-13 17:24 阅读 91 次 评论关闭

Sub Addmod()
Dim VBComp As VBComponent
Dim Code As String
'新增Modlule,并命名
Set VBComp = ThisWorkbook.VBProject.VBComponents.Add(vbext_ct_StdModule)   '新增Module1
VBComp.Name = "NewModule"
Application.Visible = True

'写入程式码
For Each rng In Range("A1:A3")
Code = Code & rng & vbCrLf
Next rng
With ActiveWorkbook.VBProject. _
VBComponents(VBComp.Name).CodeModule
NextLine = .CountOfLines + 1
.InsertLines NextLine, Code
End With
End Sub

版权声明:本文著作权归原作者所有,欢迎分享本文,谢谢支持!
转载请注明:Excel VBA高级编程:对VBA编程环境(VBE)编程 | 猎微网

评论已关闭!