In this paper, by inserting a certain thickness of the Ta and W into the Ta (5)/MgO (1)/Co2FeAl (1.5)/HM/Co2FeAl (1.5)/MgO (1)/Ta (2) multilayer films, the thermal stability of the multilayers is regulated. When Ta is inserted, the sample shows perpendicular magnetic anisotropy (PMA) in the as-deposited state, but the thermal stability is only maintained at 250 °C; when Ta is replaced with a W insertion, the thermal stability is increased to 450 °C.The XPS results show that after annealing at 350°C, Ta diffused into the ferromagnetic layer to absorb oxygen atoms, resulting in underxidation of Fe and Co, and PMA disappeared in films with Ta insertion. During the preparation of the film with W insertion, the oxygen in MgO sputtered onto the ferromagnetic layer, resulting in excessive oxidation of Fe and Co in films, so the as-deposited film shows in-plane magnetic anisotropy (IMA). However, after annealing at 350 °C, FeOx and CoOx were reduced, and some oxygen atoms returned to MgO. The oxidation state in the ferromagnetic layer is adjusted to the ideal level. Additionally, the roughness of the CFA/MgO interface of the films with W insertion was reduced, so the films with W insertion after annealing still maintained good PMA.