I'm trying to import two Excel files that have multiple sheets to Mathematica using the following code:

fileName1 = "env_air_gge-EIN-3235-v01.xls";
fileName2 = "nama_10_gdp-EIN-3235-v02.xls";
CO2EU[2] = Import[fileName1][[2]];
GDPEU[1] = Import[fileName2][[1]];
GDPEU[2] = Import[fileName2][[2]];

This is causing the following error: Syntax::sntxb: Expression cannot begin with "SetDirectory[<<733>>];".

Later I'm trying to extract some parts from the dataset that I imported using this code:

CO2emissions1985 = CO2EU[2][[12;;46, 2]];
CO2emissions1993 = CO2EU[2][[12;;46, 10]];
CO2emissions2001 = CO2EU[2][[12;;46, 18]];
CO2emissions2008 = CO2EU[2][[12;;46, 26]];
CO2emissions2017 = CO2EU[2][[12;;46, 34]];

GDPeurope1985 = GDPEU[2][[11;;55, 12]];
GDPeurope1993 = GDPEU[2][[11;;55, 20]];
GDPeurope2001 = GDPEU[2][[11;;55, 28]];
GDPeurope2008 = GDPEU[2][[11;;55, 36]];
GDPeurope2017 = GDPEU[2][[11;;55, 44]];

Which is causing this error: Part::take: Cannot take positions 12 through 46 in CO2EU[2].

I don't understand why the SetDirectory is giving this error. I would also appreciate if anyone could tell me the best way to extract only some rows and colums from the dataset in Excel. Thank you.

  • $\begingroup$ Try passing FileNameJoin[{"C:", "Users", "pablo", "Desktop", "College"}, OperatingSystem -> "Windows"] to SetDirectory. $\endgroup$ – Rohit Namjoshi Mar 30 '20 at 21:02
  • $\begingroup$ Thank for replying but it didn't work. It causes this error: Syntax::sntxf: "FileNameJoin[" cannot be followed by "{"CStyleBox[\":\", \" Code \",FontSize->12]",<<136>>,<<136>>,<<138>>,<<138>>,<<472>>,<<472>>},OperatingSystem-><<138>>]". $\endgroup$ – pablacha22 Mar 30 '20 at 21:22
  • $\begingroup$ Seems like you are using non-standard characters in your notebook. Did you copy/paste the exact code from my comment? Try that first before trying SetDirectory. $\endgroup$ – Rohit Namjoshi Mar 30 '20 at 23:03
  • 1
    $\begingroup$ I figured it out. Apparently when Mathematica updated to 12.1 the permissions were changed and it couldn't access that directory. Thank you for your help. $\endgroup$ – pablacha22 Mar 31 '20 at 19:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.