I have a valid NIE (Número de Identidad de Extranjero) NIE from my studies in Spain. I need to fly directly to Sweden and back to Johannesburg. My Spanish visa expired, but my NIE is still valid. Will they allow me to fly with the NIE, since it is for student residency in Spain and I will not be entering Spain?
You cannot use NIE for entering Sweden. And since your visa has expired you cannot enter neither Spain nor Sweden at all. NIE does not give you permission to stay in Schengen area.
You'll have to apply for a new visa.