Run VBA code and save Excels UNDO / REDO unchanged?

I run this code to force a few charts to update:

'Force update charts For Each cht In Sheets("Charts").ChartObjects cht.Chart.SeriesCollection.Add Source:=Worksheets("Builder").Range("AI2:AI7") cht.Chart.SeriesCollection(cht.Chart.SeriesCollection.Count).Delete Next cht 

I never want to cancel or repeat the lines below from the Excel Quick Access Toolbar. Unfortunately, the lines above are clear Excels undo / redo list, and I can no longer undo / undo changes.

Is it possible to force Excels undo / redo to ignore VBA code that is executed and not cleared?

+2
source share
1 answer

Is it possible to force Excels undo / redo to ignore VBA code

NO

... and not cleansed?

YES

No matter what action you perform in the Excel spreadsheet, it is stored in a list called an undo list. Therefore, when you do Undo for the first time, Excel refers to this list, and then cancels the last action that you performed.

For example, the following is the last action.

 Debug.Print Application.CommandBars("Standard").Controls("&Undo").List(1) 

You might want to see this link on Creating a Undo Handler to Undo Changes Made Using Excel VBA by Jan Karel Pieterse.

+3
source

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


All Articles