What stopped the triple alliance or the triple entente from taking countries such as Switzerland? Why didn't the Allies or Axis use this country to their advantage?
This is a pretty big question. I'll provide a brief summary here but if you want details you're going to have to be more specific.
Switzerland in World War 1
At the outbreak of the war, Switzerland kept an army of just over 200000 men at the ready. Given the geographic nature of Switzerland, the vast majority of these were deployed long the border to France although smaller units were deployed along the Italian and German borders as well.
As it became clear that the various factions of the war were going to respect the neutrality of Switzerland the army was gradually demobilized and by 1916 only 38 000 were in active serive. The number rose the following winter to some 100 000 in response to fears of a French attack through Switzerland.
Sweden in World War 1
Sweden was militarily relatively unaffected by World War 1. No party had any interest or motivation to invade. Volunteers did fight in the Finnish Civil War but in relatively small numbers.
Switzerland in World War 2
At the outbreak of WW2 Switzerland mobilized the army and maintained their policy of neutrality. They did however change their defensive planning considerably, from a static border defense to a strategy called "The national redoubt". In essence, the plan was to retreat to well fortified and well supplied defensive strong points in the high alps.
This would mean surrendering essentially all of Switzerlands economic heartland to an invader but remaining in control of crucial mountain passes and infrastructure. The general idea was to make an invasion costly for the invader while minimizing the economic damage to the country itself.
During the war several Swiss cities were bombed, both by American and German bombers, generally by accident. The damage was generally minor but it did cause some serious diplomatic tension. Switzerland also maintained a high level of activity in the air defense sector, intercepting both German and allied planes and forcing them down on Swiss airports.
Unlike World War 1 there were serious plans by Germany to invade Switzerland in World War 2 but due to the fortunes of war, these plans never came into effect.
Sweden in World War 2
By 1939 Sweden was woefully unprepared for war as a result of cut backs of the armed forces. Sweden is sometimes citizied for not supporting Finland more during the Winter War but in reality, there was little Sweden could do beyond what was done. The Swedish army was out-dated, small and ill-trained. It was only after 1942 that a military build-up began in earnest.
Sweden had two things working for it at the time, the first was the relatively unattractive geopolitical location. Germany had no real need to control Sweden with Norway already under its control and Finland as an ally and by the time it became interesting to the allies the focus of the war had shifted elsewhere (although there were allied invasion plans for Northern Sweden). The second thing was skillful political manoeuvering. Sweden did several things that were technically breeching the neutrality but generally speaking out of a realpolitical necessity.
Much of Swedens Export during the war went to Germany as any westbound trade had to cross the double Axis-Allied blockade. Some crucial parts for the British War effort continued to be smuggled out by blockade runners (my personal favourite being the HMS Gay Viking).