Selected Answer
Your own solution puts you on the correct path but it can't do what you have described. Note that the format 000# will display zero as 000. If you wish to display zero as 0000 the cell format should also be 0000.
Still with the format 000#, if you enter 1M you will get a string of "1M" ( displayed leftbound). You might use 000#\M to display a number (rightbound) 0001M but the "M" is hard-coded and must not be entered by the user.
There is no cell format solution I know or can find which would give you a string of random numbers plus characters filled with leading zeroes to a total width of 8 characters. The formula below will convert a string entered unformatted In A1 to the desired format in another cell.
=TEXT(LEFT(A1, LEN(A1)-1),"0000") & RIGHT(A1,1)
This formula works if the number is followed by a single character. It could be tweaked - at some considerable effort - to accommodate any number of trailing letters, reducing the number of leading zeroes to always create a length of 8 characters.