Using ActiveX to copy table from excel to powerpoint and keep the format.
21 views (last 30 days)
Show older comments
I use an ActiveX server to automatically create a powerpoint presentation. Therefore I open an excel file an copy a formatted table to powerpoint. The copy process works but the format is not copied. Any helps or suggestions? I tried PasteSpecial as well but the results are the same.
I kind of need a paste and keep the format function. Similar to ctrl + Alt + v.
Thank in advance.
%% Open excel and copy table
ExcelApp = actxserver('Excel.Application');
ExcelApp.Workbooks.Open("dummy_path_1"); %Import personal macros
excelWb=ExcelApp.Workbooks.Open( "dummy_path_2" ); % Open up the workbook named in the variable fullFileName.
ExcelApp.Visible = true; %Make workbook visible
ExcelApp.Run('PERSONAL.XLSB!ModifyTable'); %Run layout macro
excelWB_sheet_1=excelWb.Sheets.Item(1); %Get first sheet
excelWB_sheet_1.Range('A1:L21').Copy; %Copy table
%% Open powerpoint to paste the table
h = actxserver('PowerPoint.Application'); %Create an ActiveX object
HPresentation = h.Presentation.Open( "dummy_path_3" ); %Open an existing presentation by supplying the fullpath to the file
% select correct layout, see slide_id above
PanelLayout = HPresentation.SlideMaster.CustomLayouts.Item(9); %Number in slide in new slides
% HPresentation.Slides.count + 1 adds new slide to end of ppt
Slide = HPresentation.Slides.AddSlide(HPresentation.Slides.count + 1, PanelLayout);
Slide.Select
Slide.Shapes.Paste % Paste table but the format is not pasted
%Slide.Shapes.PasteSpecial % Works but same result as Paste()
0 Comments
Answers (1)
Cris LaPierre
on 27 Jan 2023
I looked at the Shapes.PasteSpecial docuemntation page. I think you need to tell it what datatype format to use when pasting. Try this:
Slide.Shapes.PasteSpecial(2) % 2 = enhanced Metafile
See Also
Categories
Find more on Spreadsheets in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!