You can use a weapon that has the ammunition property to make a ranged attack only if you have ammunition to fire from the weapon. Each time you attack with the weapon, you expend one piece of ammunition. Drawing the ammunition from a quiver, case, or other container is part of the attack (you need a free hand to load a one-handed weapon).
If you use a weapon that has the ammunition property to make a melee attack, you treat the weapon as an improvised weapon, unless stated otherwise.