I see this question a lot. Allow me to attempt an answer.
The Excelsior class is analogous to the Klingon D7/K't'inga, in as much as it's the backbone of the Federation fleet. Now, I don't know whether any of this has been said in canon/non-canon sources, and I'm just kinda "filling in" the time between the Enterprise-B era and when TNG began with my own imaginings and deductive reasoning, so take it with a grain of salt.
During the time period I stated above, the Federation was in a state of relative peace. Sure, they had skirmishes, and "incidents", but nothing major. This is kind of inferred in canon. Before Voyager began, Robert Picardo did a kind of "introductory" special on UPN. One statement he made was that by the time of Kirk's era, the Federation had explored 3% of the galaxy, and by the TNG era, that number had risen to 19%.
When the Enterprise-B was launched, the Excelsior class was likely still the most advanced in the fleet. Now, during peacetime, military organizations (don't be deluded here, Starfleet IS a military organization, though their primary mission is exploration) tend to scale back production of hardware to a level that meets an acceptable readiness level. Development of new hardware also takes a cut. During this time, while they weren't building (or designing) as many (new) ships as they might have been before the Khitomer Accords, they were at peace, which meant few starships being lost due to combat. Of course, Starfleet probably never builds only one class of ship at a time, but the Excelsior class probably remained the most advanced and at the top of the build list for quite a while. What this means is that the Excelsior class was built more than any other class over a protracted period of time. By the TNG era, they would likely have made up the bulk of Starfleet. Of course, other more advanced ships were developed and built, but probably not at a rate that would allow them to overshoot the Excelsior class in number. Starfleet probably recognized that they had a pretty sturdy and "modifiable" design with the Excelsior class, and there being no immediate need for more advanced ships beyond designing and building new ships for the sake of doing so, stuck with the design. Add to this that as time goes on, shipyard personnel get more and more accustomed to building a single class and materials become more readily available, it's easy to see why there are so many in service by the TNG era.
According to the TNG tech manual (I know, not strictly canon), Federation starships receive minor refits (swapping of easily replaceable systems) every 7 years and major overhauls (adding new systems, replacing the hull with stronger materials, replacing the warp and impulse engines and various other "inner workings") every 20 years, with a predicted design lifetime of 100 years, when it is probable that such an old design simply can't handle new systems and it's simply more feasible to scrap a ship and build a more advanced ship in its place, or 100 years of use has rendered the ship no longer spaceworthy. Of course, by 2409, the Excelsior class has reached this lifetime "limit". However, for approximately 10 years now, the Federation has been challenged time and again, and scrapping so many ships to build new ones is just asking for trouble. Not to mention the fact that encounters with the Borg and the Dominion War has probably left Starfleet reluctant to scrap old ships as readily as they would have before the TNG era.
So! If you made it through all that, I applaud you. I hope this answers the question. I tried to use as much deductive reasoning as I could, given the availability of canon information.
If anyone has more questions, or feels my analysis needs some CONSTRUCTIVE criticism, then by all means, question and criticize. If you're just going to spout "ur wrong, lulz", or "I don't agree, therefore you're wrong", and leave it at that, then please, stay away from the reply button.
EDIT: I realize now that with the next to last sentence, I may have opened myself up to people saying those things just to be "funny".
Lets not also forget that with a lifetime of 100 years for a new build, a new build in 2350 would be expected to last until 2450, and so on and so forth. New builds commissioned later will stay in service well after the first production line is completely retired.
As stated by the OP Federation starships were known for their modular designs for multiple roles. A spaceframe/design such as the Excelsior would give it plenty of options to be upgraded over the years for continued service. Even now in the Borg/Klingon War It would stand to reason alot of mothballed Excelsiors would be retrofitted back into service (See Excelsior retrofit) Good Example is IRL The United States still have bombers (B-52) in service since the 1950s. Imagine how much more longer ships could be made to last hundreds of years in the future. I am being completely objective here despite the fact that the Excelsior class has and will always be my favorite canon starship .
To expand on the above, aside from wars with the Tzenkethi and Cardassians and some brief skirmishes with the Romulans, Starfleet's not needed a massive military force until the Borg incursion at Wolf 359. It's likely a lot of perfectly serviceable ships were mothballed. We saw several perfectly useable looking ships laid up at the (Rator VII?) supply depot in "Unification" for example.
A ship that's laid up is essentially inert, no stress is being exerted on it's space frame, and a quick once over and restoration means it'll essentially be as "new" as when it was laid up, especially with the preservative quality of a vacuum, therefore it's safe to conclude that many Excelsior's had their useful service life "paused" at some point.
Interestingly, the above is also a large part of why the USAF has plans to, and will likely achieve, almost 90 years of using the B-52 strategic bomber, I belive the TU-95 Bear will also be comporable in service life. Since it's introduction in the 50's it's (B-52) remained one of the largest, and certainly the most efficient means to deliver heavy ordnance around the Globe. Just about everything's been replaced (avionics, engines, munitions, even cockpit) at some point but the airframe, but there are hundreds that are "mothballed" in the desert that could easily be refurished, and these planes are not putting any stress on their aiframe, no metal fatigue is occuring, so they can easily be returned to service long after one flying around since 'Nam would've been retired.