0

I have a very simple code which runs without errors when run from inside VBA , using F5 command.

Nevertheless if I try to run the code stept by step using F8 even though it inserts the object it throws the message "Can't enter break mode at this time" and this bothers me because I want to debug the code and I can not do it.

I have isolated the code in order for your help:

Sub Macro1()  
    Set objWorkbook = ActiveWorkbook Set ob = objWorkbook.ActiveSheet.OLEObjects

    ob.Add(ClassType:="Forms.TextBox.1", Link:=False, _
            DisplayAsIcon:=False, Left:=67.5, Top:=54, Width:=177.75, Height:= _
            35.25).Select 
End Sub
braX
  • 11,506
  • 5
  • 20
  • 33
Andrei
  • 155
  • 1
  • 1
  • 7
  • You're out of luck. OLEObjects become part of the workbook's project, so your code will actually cause state loss, which is why you can't enter break mode there. – Rory Oct 23 '18 at 08:15
  • I can not enter break mode even after that statement. It seems as soon as VBA sees the OleObjects code does not allow to enter break mode. There is no chance to overtake it ? – Andrei Oct 23 '18 at 08:23
  • That's why I said you're out of luck. Once the state loss has occurred, that's it. The only way to step through code after that would be to make it a separate routine called by say an `OnTime` routine so that the project can reset in between. – Rory Oct 23 '18 at 08:40
  • @rory could you elaborate on the `OnTime` technique you speak of..? This sound like something to do with worksheet events..? Or is this the hardcore one through WinAPI..? – spinjector Aug 14 '19 at 19:47
  • @spinjector Just put the subsequent code into a separate routine and then call it using `application.ontime` – Rory Aug 15 '19 at 11:33
  • Thank you. I get deep in Excel & Access VBA, and this is yet another new one that I've only just learned of from someone; it happens regularly. Interestingly, I think I can also use this when developing Extensibility code with VBIDE. It has the same issue of state loss, which makes sense since it does the same kind of noodling about in the XML widgets in the project. – spinjector Aug 15 '19 at 13:25

0 Answers0