PDA

View Full Version : New learner need help - convert tables in word format to ppt slides.



sas
09-21-2017, 06:38 PM
Hello all.

I am new learner in VBA, and writing some VBscript in SAS.

I want to convert tables in word format (.rtf) to ppt slides (.ppt). The following is my code, which could copy the first table in the specific word file, paste into a new ppt file and save under certain folder. I need help on these two questions.

1. How to get the number of tables in the word file?
2. Once I got the number of tables, how to write a loop and copy/paste each table into the ppt file? Each table will be on one slide of ppt file.

Thank you very much!



filename script "C:\Users\zzz\Desktop\New\wdtb2ppt.vbs";

data _null_;
file script;
put 'Set objWord = CreateObject("Word.Application")';
put 'objWord.Visible = False';
/* Slide 1*/
put 'Set objDoc = objWord.Documents.Open("' "C:\Users\zzz\Desktop\New\t_aesum_age_saf.rtf"'")';
put 'Set objSelection = objWord.Selection';
put 'Set objPPT = CreateObject("PowerPoint.Application")';
put 'objPPT.Visible = True';
put 'Set objPresentation = objPPT.Presentations.Add';
/* put 'objPresentation.ApplyTemplate("C:\temp\tmp3.pot")';*/
put 'objDoc.Activate';
put 'objDoc.Tables(1).Range.Select';
put 'objSelection.Copy';
put 'Set objSlide = objPresentation.Slides.Add(1,12)';
put 'objPPT.ActiveWindow.View.Paste';

put 'objPresentation.SaveAs("C:\Users\zzz\Desktop\New\table.ppt")';
put 'objPresentation.Close';
put 'objPPT.Quit';
put 'objDoc.Close';
put 'objWord.Quit';
run;

filename xx pipe "cscript //nologo ""C:\Users\zzz\Desktop\New\wdtb2ppt.vbs""";
data _null_;
infile xx;
input;
put _infile_;
run;

sas
09-21-2017, 08:15 PM
Here is my code in VBS file.

Set objWord = CreateObject("Word.Application")
objWord.Visible = False
Set objDoc = objWord.Documents.Open("C:\Users\zzz\Desktop\New\t_aesum_age_saf.rtf")
Set objSelection = objWord.Selection
Set objPPT = CreateObject("PowerPoint.Application")
objPPT.Visible = True
Set objPresentation = objPPT.Presentations.Add
objDoc.Activate
objDoc.Tables(1).Range.Select
objSelection.Copy
Set objSlide = objPresentation.Slides.Add(1,12)
objPPT.ActiveWindow.View.Paste
objPresentation.SaveAs("C:\Users\zzz\Desktop\New\table.ppt")
objPresentation.Close
objPPT.Quit
objDoc.Close
objWord.Quit

macropod
09-21-2017, 08:33 PM
Cross-posted at: http://www.msofficeforums.com/word-vba/36849-new-learner-need-help-convert-tables-word.html
Please read Mr Excel's policy on Cross-Posting in rule 13: http://www.mrexcel.com/forum/board-announcements/99490-forum-rules.html