I'm trying to reuse my code module for loop runs (which will change some data during different loop);however, I realized the from 2nd loop onwards, the macro is still running the old script. Any idea how I can ensure that the macro runs the updated script (which I will always delete and re-create during every loop)?
The actual scrip is very long, to simplify it i will just extract the area which I'm referring to. I have no error running this, just that from 2nd loop onwards, I checked that the module I re-created has the updated script, but macro still running the first loop script, which is very strange for me.
The script to be written into module is stored in excel sheet3 and it changes after every new loop starts
Sub write_module()
For i = 1 To 2
Dim VBProj As VBIDE.VBProject
Dim VBComp, comp As VBIDE.VBComponent
Dim CodeMod As VBIDE.CodeModule
Set VBProj = ActiveWorkbook.VBProject
Set VBComp = VBProj.VBComponents("ZC553_MS")
Set CodeMod = VBComp.CodeModule
script_lr = Sheet3.Cells(Rows.Count, 8).End(xlUp).Row
LineNum = 2
With ActiveWorkbook.VBProject.VBComponents("ZC553_MS").CodeModule
' .DeleteLines 2, VBComp.CodeModule.CountOfLines - 2
For j = 1 To script_lr
.InsertLines LineNum, Sheet3.Cells(j, 8)
LineNum = LineNum + 1
Next j
End With
zc553_master
Next i
End Sub