How can I use a 240 volt circuit for 240v and 120v appliance as per code?
If the microwave is going to be plugged in to a receptacle, which almost all are, then the following articles apply:

406.4 General Installation Requirements.  Receptacle outlets shall be located in branch circuits in accordance with Part III of Article 210. General installation requirements shall be in accordance with 406.4(A) through (F).
(A) Grounding Type.  Except as provided in 406.4(D) [this refers to replacing old two prong receptacles and doesn't apply to your case], receptacles installed on 15- and 20-ampere branch circuits shall be of the grounding type. Grounding-type receptacles shall be installed only on circuits of the voltage class and current for which they are rated, except as provided in Table 210.21(B)(2) and Table 210.21(B)(3).

This is a crude recreation of the Table, notice 40 amp circuits require 40 amp receptacles.

Table 210.21(B)(3) Receptacle Ratings for Various Size Circuits
Circuit Rating (Amperes) : Receptacle Rating (Amperes)
15 : Not over 15
20 : 15 or 20
30 : 30
40 : 40 or 50
50 : 50

This means a receptacle on a 40 amp circuit has to be rated 40 or 50 amps.
If your microwave is hard-wired, then there is an exception to allow taps on a 50 amp circuit but not on anything smaller so this exception does not apply to your 40 amp circuit.

210.19(A)(3) Exception No. 1: Conductors tapped from a 50-ampere branch circuit supplying electric ranges, wall-mounted electric ovens, and counter-mounted electric cooking units shall have an ampacity of not less than 20 amperes and shall be sufficient for the load to be served. These tap conductors include any conductors that are a part of the leads supplied with the appliance that are smaller than the branch-circuit conductors. The taps shall not be longer than necessary for servicing the appliance. [This means the microwave would have to be hard-wired with minimum #12 wire.]

So, after reading through these articles, my opinion is that you will need to run a separate circuit for the microwave. And as long as you are doing it, you should make it a 20 amp circuit to allow for a higher powered microwave. In this case, doing the difficult thing is the safer and Code compliant thing.
Good luck!