Macro to force Excel to exit edit mode

I have a macro that needs to be run to update.

If Excel is in the editor, I need a macro to have Excel editing mode, i.e. take control.

+3
source share
2 answers

The natural way to do this is to use the Application.OnTimer method, but it has the “editing problem” that you just noted. The called function will not be executed until the user leaves the editing mode.

You can overcome this: this solution is not very efficient, but you can take control of the macro and return it from the timer (or any other event that you choose).

Excel.

( ), .

Sub a()
  Dim PauseTime, Start, Finish, TotalTime
  If (MsgBox("Press Yes to fire update in 1000 secs", 4)) = vbYes Then
      PauseTime = 1000    ' Set duration 1000 secs or whatever.
      Start = Timer    ' Set start time.
      Do While Timer < Start + PauseTime
          DoEvents    ' Yield to other processes - THIS IS THE TRICK
      Loop
      Finish = Timer    ' Set end time.
      TotalTime = Finish - Start    ' Calculate total time.
      MsgBox "Paused for " & TotalTime & " seconds" 'Program your update HERE
   Else
     End
  End If
End Sub

, , .
, , , .

, , .

+1

, Excel - .

+2

Source: https://habr.com/ru/post/1761595/


All Articles