At the Vatican, the strict dress code pertains to St. Peter's Basilica. So anyone going unprepared, you may still tour the museums and other areas which don't have the dress code. But, a visit to the Vatican wouldn't be complete without the visit to St. Peter's even for those of us who are not Catholic. Yes it is a place of worship so you must be respectful in manner and dress. But many people do at the last minute throw on a wrap around shawl or skirt around their waste (even a blanket) or a shawl over their shoulders. I don't mean any disrespect to the previous poster or anyone else reading this but it is a major tourist attraction so the security is mainly concerned with what is showing, not exactly what you are wearing to cover it up. Men definitely cannot wear shorts, even below the knees. The first time we visited, I was not allowed so we had to return the next day. Many other churches in Europe allow long shorts, not the Vatican. Bring a pair of warmups or thin pants to wear over your shorts. T-shirts are definitely allowed. Yes, you don't have to wear a suit or dress, but we've seen many fashion statements not showing shoulders or knees.
But you MUST visit there. And don't miss the Sistine Chapel, absolutely breathtaking, in my opinion of course.