Consulting

Results 1 to 3 of 3

Thread: VBA/VBE Weird behavior when deleting a code line in a sub using a different sub

  1. #1

    VBA/VBE Weird behavior when deleting a code line in a sub using a different sub

    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: untitled.bmp) 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
    Last edited by SamT; 02-17-2016 at 07:59 PM. Reason: added CODE TAgs with editor' # Icon

  2. #2
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    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
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  3. #3
    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!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •