Welcome to the CADTutor forums, probably the most lively and friendly AutoCAD forums on the web. You will need to register in order to post a question and to see all the content on this board. See How to register for details. Use the Lost password recovery form if you ever forget either your password or username. Be sure to check out the FAQ for more information.

If the suggestion(s) offered are ineffective when adding steps not listed in the OP, then we didn't have enough information to begin with.

Separately, use the code I posted again, and instead of issuing the CHANGE command, use the Properties Palette (Ctrl+1 if not already open), and with all 46 Viewports selected, change the layer from the Properties Palette... as this example shows:

... All 46 Viewports WILL change layers as your command line output attempted to do.

*IF* your goal is to programmatically change the layer for each Viewport Entity throughout all tabs of a given Drawing, then you need to specify that, in addition to any other steps you want accomplished. I'd be happy to help, but I need complete information.