我一直在研究使用VBA编写VBA代码。因此,最终我可以根据输入的变量编写一个算法来编写循环。
我遇到了下面的内容,看起来好像它会为VBA项目添加代码,但我错过了一些工作的东西。在这个问题上苦苦挣扎。我知道' ThisWorkbook'是问题。任何想法,我需要称之为能够在VBA项目中引用该表(同名)。
由于
Option Explicit
Sub test()
Dim WB_Write_Code_Test As Workbook
Dim WS_Test As Worksheet
Dim nextline As Long
Set WB_Write_Code_Test = Workbooks.Open("Write Code Test")
Set WS_Test = WB_Write_Code_Test.Sheets("Test")
With ActiveWorkbook.VBProject. _
VBComponents(ThisWorkbook).CodeModule
nextline = .CountOfLines + 1
.InsertLines nextline, WS_Test.Cells(1, 1).Value
End With
End Sub
答案 0 :(得分:1)
谢谢,已经做到了。
供参考,缺少的代码是:
VBComponents(ThisWorkbook.CodeName).CodeModule