我一直在研究使用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发布于 2017-08-29 00:49:58
谢谢,这样就行了。
作为参考,缺少的代码是:
VBComponents(ThisWorkbook.CodeName).CodeModulehttps://stackoverflow.com/questions/45921728
复制相似问题