Since firearms were introduced to the battlefield because armor got so effective that bows and crossbows couldn't penetrate it. By the 18th century armor and melee weapons had mostly disappeared from the battlefield but I would imagine if a group of soldiers were to arm themselves they'd be able to dominate their opponents with faster more accurate weapons. Same thing with spears.
Very similar question with a great response from u/tiako: https://www.reddit.com/r/AskHistorians/comments/18984h/the_bow_is_better_than_the_musket_why_did/
How early in the 18th century are you talking? I'm not sure about early 18 century firearms, but late 18th to early 19th century firearms would be able to pierce most armor.
Firearms were also easier to make and much easier to use, cutting down training time.
Spears were basically included on muskets with the invention of the bayonet.
If you are wondering why the bow fell out of use completely in europe and why european monarchs didn't bother trying to train small, elite units of archers for special roles, then you might be interested in this post here. In short, bows did still see some use outside of europe such as in North America, India and China during the 18th and 19th centuries, but encounters with these archers don't seem to have given Europeans the impression that their firearms were in any way inferior. To give an English example from the first Opium war: "[A Qing Officer] with cool determination and a steady aim, deliberately discharged four arrows from his bow at Captain Hall, fortunately without effect. Had they been musket-balls, however, he could scarcely have escaped. A marine instantly raised his musket at the less fortunate chinese officer: the aim was unerring and he fell."
In short, the range and accuracy of bows compared to musket seems to have been greatly exaggerated. Nor is it really accurate to say that muskets only replaced bows because of armor (Musketeers had generally stopped wearing body armor well before England's privy council declared the longbow obsolete in 1595).
If I had to say the biggest reason though seems to be that even after armor was abandoned, the extra stopping power and overpenetration of a musket was still generally considered extremely important in combat. It was well known at the time that even smoothbore weapons could be made more accurate and more manageable by making them a smaller caliber or using a smaller powder charge. In Bosworth's A Treatise of the Rifle, Musket, Pistol, and Fowling-piece he concluded that by reducing the gunpowder charge to around 1/8th the weight of the ball, the diameter spread of a standard military musket could be reduced by half. Yet militaries still generally concluded that the ability to shatter bones and blast clean through someone was more important than raw accuracy.