Error using Interface.​000208D7_0​000_0000_C​000_000000​000046/get Invoke Error, Dispatch Exception: El índice no es válido.

2 views (last 30 days)
Cómo puedo solucionar aquel error, ya que si cambio el valor sheet2 = get(Sheets, 'Item', 2); -a- sheet2 = get(Sheets, 'Item', 1); No aparece el error pero yo quiero crear la segunda hoja y guardar ahí un gráfico.
El gráfico antes hecho:
x=-2.9:0.2: 2.9; y=exp(-x.*x); plot(x,y)
El código es el siguiente:
function PlotInExcel
FILE = 'C:\victor\test_plot.xls';%.............Archivo
%.............excel COM objetos............................................................................
Excel = actxserver ('Excel.Application');
Excel.Visible = 1;
if ~exist(FILE,'file')
ExcelWorkbook=Excel.Workbooks.Add; %NUEVO LIBRO DE EXCEL
ExcelWorkbook.SaveAs(FILE);
ExcelWorkbook.Close(false);
end
invoke(Excel.Workbooks,'Open',FILE); %Abre la carpeta
Sheets = Excel.ActiveWorkBook.Sheets;
sheet2 = get(Sheets, 'Item', 2);
invoke(sheet2, 'Activate');
Activesheet = Excel.Activesheet;
print ('-f1','-dmeta'); %.................Copiando a los portapapeles
Range ='A1';
ActiveSheetRange = get(ActiveSheet,'Range',Range);
ActiveSheetRange.Select;
ActiveSheetRange.PasteSpecial; %.................pegando la figura en la localización asignada
end
%-----------------------------------fin de la función "PlotInExcel--------------------------------------

Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!