diff --git a/matlab/WriteShockDecomp2Excel.m b/matlab/WriteShockDecomp2Excel.m
index 7378115701aaeedd4092fb503ca5835f0045d91b..f339f294e223ee90f3743389cb6c0f7c4565980c 100644
--- a/matlab/WriteShockDecomp2Excel.m
+++ b/matlab/WriteShockDecomp2Excel.m
@@ -28,7 +28,9 @@ function WriteShockDecomp2Excel(z,shock_names,endo_names,i_var,initial_date,Dyna
 % You should have received a copy of the GNU General Public License
 % along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
 
-SteadyState=[];
+OutputDirectoryName = CheckPath('Output',DynareModel.dname);
+
+SteadyState=zeros(DynareModel.endo_nbr,1);
 fig_mode='';
 fig_mode1='';
 fig_name='';
@@ -114,15 +116,13 @@ for j=1:nvar
     end
 
     warning off
-    try
-        [STATUS,MESSAGE] = xlswrite([DynareModel.fname,'_shock_decomposition',fig_mode,fig_name1],d0,endo_names{i_var(j)});
-    catch
-        if exist('xlwrite.m','file')
-            [STATUS] = xlwrite([DynareModel.fname,'_shock_decomposition',fig_mode,fig_name1],d0,endo_names{i_var(j)});
-        else
-            fprintf('\nWriteShockDecomp2Excel: could not write Excel file. It seems Excel is not installed on your machine.\n')
-            fprintf('Please install the free xlwrite.m from https://mathworks.com/matlabcentral/fileexchange/38591-xlwrite-generate-xls-x-files-without-excel-on-mac-linux-win\n')
-        end
+    fig_name1 = strrep(fig_name1,' ','_');
+    fig_name1 = strrep(fig_name1,'.','');
+    
+    if ~ismac
+        [STATUS,MESSAGE] = xlswrite([OutputDirectoryName,filesep,DynareModel.fname,'_shock_decomposition',fig_mode,fig_name1],d0,endo_names{i_var(j)});
+    else
+        writetable(cell2table(d0), [OutputDirectoryName,filesep,DynareModel.fname,'_shock_decomposition',fig_mode,fig_name1 '.xls'], 'Sheet', endo_names{i_var(j)},'WriteVariableNames',false);
     end
     warning on
 
diff --git a/matlab/expand_group.m b/matlab/expand_group.m
index 0992e4967d975c26483b508d334d8a4c89492ad3..a216b51b1a63f8ec6bada950e0c79d5d935612a0 100644
--- a/matlab/expand_group.m
+++ b/matlab/expand_group.m
@@ -1,4 +1,4 @@
-function expand_group(use_shock_groups,var_list_, ic)
+function expand_group(use_shock_groups,var_list_, ic, no_graph)
 % function expand_group(use_shock_groups,var_list_, ic)
 % Expands shocks contributions out of a group of shocks
 %
@@ -27,6 +27,9 @@ function expand_group(use_shock_groups,var_list_, ic)
 % You should have received a copy of the GNU General Public License
 % along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
 
+if nargin<4
+    no_graph=0;
+end
 filename = get(gcf,'filename');
 [filepath, name, ext]=fileparts(filename);
 M = evalin('base','M_');
@@ -56,7 +59,12 @@ M.exo_names = mydata.exo_names;
 options.plot_shock_decomp.interactive=0;
 options.plot_shock_decomp.expand=1;
 options.plot_shock_decomp.nodisplay=0;
-options.plot_shock_decomp.write_xls=0;
+if no_graph
+    options.no_graph.plot_shock_decomposition=1;
+    options.plot_shock_decomp.write_xls=1;
+else
+    options.plot_shock_decomp.write_xls=0;
+end
 %% set optimal colormap
 func = @(x) colorspace('RGB->Lab',x);
 MAP = distinguishable_colors(length(shocks)+1,'w',func);
diff --git a/matlab/graph_decomp.m b/matlab/graph_decomp.m
index 60a0acb5d50e3e6c90f406107ec7f0bd1ea09d6e..f00512a2a32a7df9bc0a4985907974519f91b8e3 100644
--- a/matlab/graph_decomp.m
+++ b/matlab/graph_decomp.m
@@ -227,6 +227,8 @@ for j=1:nvar
                 browse_menu = uimenu(c,'Label','Browse group');
                 expand_menu = uimenu(c,'Label','Expand group','Callback',['expand_group(''' mydata.plot_shock_decomp.use_shock_groups ''',''' mydata.plot_shock_decomp.orig_varlist{j} ''',' int2str(i) ')']);
                 set(expand_menu,'UserData',mydata,'Tag',['group' int2str(i)]);
+                save_expand2xls_menu = uimenu(c,'Label','Export group to xls','Callback',['expand_group(''' mydata.plot_shock_decomp.use_shock_groups ''',''' mydata.plot_shock_decomp.orig_varlist{j} ''',' int2str(i) ', 1)']);
+                set(save_expand2xls_menu,'Tag',['xls_group' int2str(i)]);
                 for jmember = mydata.shock_group.shocks
                     uimenu('parent',browse_menu,'Label',char(jmember))
                 end
diff --git a/matlab/graph_decomp_detail.m b/matlab/graph_decomp_detail.m
index b19a226b8b5978fdcd1b1108cfbd8da36a44496d..89111f987eaaa5efaac971e2917bcd1392a48af9 100644
--- a/matlab/graph_decomp_detail.m
+++ b/matlab/graph_decomp_detail.m
@@ -24,7 +24,7 @@ function []=graph_decomp_detail(z,shock_names,endo_names,i_var,initial_date,Dyna
 % but WITHOUT ANY WARRANTY; without even the implied warranty of
 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 % GNU General Public License for more details.
-%xf
+%
 % You should have received a copy of the GNU General Public License
 % along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
 
@@ -233,6 +233,8 @@ for j=1:nvar
                     browse_menu = uimenu(c,'Label','Browse group');
                     expand_menu = uimenu(c,'Label','Expand group','Callback',['expand_group(''' mydata.plot_shock_decomp.use_shock_groups ''',''' mydata.plot_shock_decomp.orig_varlist{j} ''',' int2str(ic) ')']);
                     set(expand_menu,'UserData',mydata,'Tag',['group' int2str(ic)]);
+                    save_expand2xls_menu = uimenu(c,'Label','Export group to xls','Callback',['expand_group(''' mydata.plot_shock_decomp.use_shock_groups ''',''' mydata.plot_shock_decomp.orig_varlist{j} ''',' int2str(ic) ', 1)']);
+                    set(save_expand2xls_menu,'Tag',['xls_group' int2str(ic)]);
                     for jmember = mydata.shock_group.shocks
                         uimenu('parent',browse_menu,'Label',char(jmember))
                     end
diff --git a/matlab/plot_shock_decomposition.m b/matlab/plot_shock_decomposition.m
index 11ca3b005abc8b3ed29c760dd95443398a9fb6aa..68c142bd3e61f19822d6966ebd8ed7998f7ea53c 100644
--- a/matlab/plot_shock_decomposition.m
+++ b/matlab/plot_shock_decomposition.m
@@ -50,7 +50,7 @@ if size(varlist,1) == 0
     end
 end
 
-if isfield(options_.plot_shock_decomp,'init2shocks') % private trap for uimenu calls
+if isfield(options_.plot_shock_decomp,'init2shocks') && options_.plot_shock_decomp.realtime==0 % private trap for uimenu calls
     init2shocks=options_.plot_shock_decomp.init2shocks;
 else
     init2shocks=[];
@@ -59,7 +59,7 @@ if ~isempty(init2shocks)
     init2shocks=M_.init2shocks.(init2shocks);
 end
 
-
+orig_endo_names = M_.endo_names;
 epilogue_decomp=false;
 if exist_varlist && any(ismember(varlist,M_.epilogue_names))
     epilogue_decomp=true;
@@ -252,15 +252,15 @@ if ~isempty(init2shocks) && ~expand
     n=size(init2shocks,1);
     M_.exo_names_init=M_.exo_names;
     for i=1:n
-        j=strmatch(init2shocks{i}{1},M_.endo_names,'exact');
+        j=strmatch(init2shocks{i}{1},orig_endo_names,'exact');
         if ~isempty(init2shocks{i}{2})
             jj=strmatch(init2shocks{i}{2},M_.exo_names,'exact');
-            M_.exo_names_init{jj}=[M_.exo_names_init{jj} ' + ' M_.endo_names{j}];
-            z(:,jj,:)= z(:,jj,:) + oo_.initval_decomposition (:,j,:);
+            M_.exo_names_init{jj}=[M_.exo_names_init{jj} ' + ' orig_endo_names{j}];
+            z(:,jj,:)= z(:,jj,:) + oo_.initval_decomposition (:,j,1:size(z,3));
         else
-            z(:,end,:)= z(:,end,:) - oo_.initval_decomposition (:,j,:);
+            z(:,end,:)= z(:,end,:) - oo_.initval_decomposition (:,j,1:size(z,3));
         end
-        z(:,end-1,:)= z(:,end-1,:) - oo_.initval_decomposition (:,j,:);
+        z(:,end-1,:)= z(:,end-1,:) - oo_.initval_decomposition (:,j,1:size(z,3));
 
     end
 end
@@ -271,6 +271,9 @@ if ~epilogue_decomp
     else
         steady_state = oo_.steady_state;
     end
+    if isfield(oo_.shock_decomposition_info,'i_var') && (M_.endo_nbr<length(orig_endo_names))
+        steady_state=steady_state(oo_.shock_decomposition_info.i_var);
+    end
 else
     steady_state = oo_.shock_decomposition_info.epilogue_steady_state;
 end