PDA

View Full Version : [SOLVED] VBA/VBE Weird behavior when deleting a code line in a sub using a different sub



Patrickll
02-17-2016, 04:21 PM
Hi, here is my situation. I am using a .deleteLines to delete certain lines of code in a Sub. Whenever the .deleteLines happens, a popup appears (added as a screenshot: 15425) mentioning Break is pretty much disabled going forward. From that moment, it is impossible for me to break at a specific line after the .deleteLines code line. My first question is: Is this avoidable? and 2nd question: If not, is there a way to reactivate Breaks?

Workbook1 opens Workbook 2 using Application.Run MacroName

MacroName (in Workbook2) uses the following code to delete certain lines:


ModuleName = "MyModule"


Set VBProj = ActiveWorkbook.VBProject
Set VBComp = VBProj.VBComponents(ModuleName)
Set CodeMod = VBComp.CodeModule
Dim SLS As Long ' start line
Dim SCS As Long ' start column
Dim ECS As Long ' end column
Dim SLE As Long ' start line
Dim SCE As Long ' start column
Dim ECE As Long ' end column


SLS = 1
SCS = 1
ECS = 255


SLE = 1
SCE = 1
ECE = 255


With CodeMod
FoundStart = .Find(Target:=StartCode & AddedVariable, StartLine:=SLS, StartColumn:=SCS, EndLine:=.CountOfLines, EndColumn:=ECS, wholeword:=True, MatchCase:=False, patternsearch:=False)
FoundEnd = .Find(Target:=EndCode & AddedVariable, StartLine:=SLE, StartColumn:=SCE, EndLine:=.CountOfLines, EndColumn:=ECE, wholeword:=True, MatchCase:=False, patternsearch:=False)


LineStart = SLS + 1
LineEnd = SLE - 1
NumberofLinestoDelete = SLE - LineStart


.DeleteLines LineStart, NumberofLinestoDelete


End With

Any help would be greatly appreciated!

Thanks

SamT
02-17-2016, 08:07 PM
I analyzed this part. I don't know why you are doing it this way, but my analysis may help you understand it better.

With CodeMod
'FoundStart is not used
FoundStart = .Find(Target:=StartCode & AddedVariable, StartLine:=SLS, StartColumn:=SCS, EndLine:=.CountOfLines, EndColumn:=ECS, wholeword:=True, MatchCase:=False, patternsearch:=False)

'FoundEnd is not used
FoundEnd = .Find(Target:=EndCode & AddedVariable, StartLine:=SLE, StartColumn:=SCE, EndLine:=.CountOfLines, EndColumn:=ECE, wholeword:=True, MatchCase:=False, patternsearch:=False)

LineStart = SLS + 1
'LineStart = 2

LineEnd = SLE - 1
'LineEnd = 0

NumberofLinestoDelete = SLE - LineStart
'NumberOfLinesToDelete = -1

Patrickll
02-17-2016, 09:07 PM
Somehow simply using Application.OnTime Now + TimeValue("00:00:01"), "test1" seems to have do the trick. My problem was that as soon as my code was modified by my own macro, the debugger "kind of" fails, until the process reaches end sub. By adding the ontime 1 sec delay before the end sub instead of calling the next sub, it resets the debugger!