469,361 Members | 2,291 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,361 developers. It's quick & easy.

Merge Powerpoint presentations

Hi,

What I'm trying to do is,

once the users select the files they want to merge, they select a button which will:

1. Open an instance of powerpoint
2. Open the first of the files selected by the user
3. Copy/ export that slides from that presentation
4. Paste into the instance of powerpoint (in point 1 above)
5. Close the first file
... repeat these steps for all the rest of the files selected by the user

I know what needs to be done but I have no idea how to go about the syntax in VB/ C#

//I know I need to have the following directive:
Expand|Select|Wrap|Line Numbers
  1. using PowerPoint = Microsoft.Office.Interop.PowerPoint;
  2.  
//Maybe the following:
Expand|Select|Wrap|Line Numbers
  1. PowerPoint.Application oPPT;
  2. PowerPoint.Presentations objPresSet;
  3.  
//the location of your powerpoint presentation
Expand|Select|Wrap|Line Numbers
  1. string strPres;
  2. strPres = @"mpPres.ppt";
  3.  
But have no idea where to go from here ...

Any help would be very much appreciated ..

Thanks

J
May 9 '07 #1
35 12669
SammyB
807 Expert 512MB
Do you really need to do this in .Net? Seems like a PowerPoint macro would be a lot easier. In any case, I would do it as a macro first, because you can record a macro to see how to do it. Then switch back to .Net. That is what I would have to do in order to help you. Try that and post back if you have trouble with anything specific. --Sam
May 9 '07 #2
Do you really need to do this in .Net? Seems like a PowerPoint macro would be a lot easier. In any case, I would do it as a macro first, because you can record a macro to see how to do it. Then switch back to .Net. That is what I would have to do in order to help you. Try that and post back if you have trouble with anything specific. --Sam
Hi,

This is the macro that I've created that works:

Expand|Select|Wrap|Line Numbers
  1. Sub Macro6()
  2.  
  3.     Dim PPApp As PowerPoint.Application
  4.     Dim PPPres As PowerPoint.Presentation
  5.     Dim PPSlide As PowerPoint.Slide
  6.  
  7.     ' Create instance of PowerPoint
  8.     Set PPApp = CreateObject("Powerpoint.Application")
  9.  
  10.     ' Create a presentation
  11.     Set PPPres = PPApp.Presentations.Add
  12.  
  13.  
  14. Dim nSlides As Integer
  15. Dim fnames As New Collection
  16. fnames.Add "Blah1.ppt"
  17. fnames.Add "Blah2.ppt"
  18. 'fnames.Add "p3.ppt"
  19. 'fnames.Add "p4.ppt"
  20. 'fnames.Add "p5.ppt"
  21. For Each fnam In fnames
  22.   nSlides = ActivePresentation.Slides.InsertFromFile(fnam, ActivePresentation.Slides.Count)
  23. Next
  24. End Sub
  25.  
  26.  
May 10 '07 #3
SammyB
807 Expert 512MB
We are geniuses: I've just about finished the same solution in C#. I'll post it when it works. Hope it's not 4:30 AM where you are like it is here! :)
May 10 '07 #4
4:30 ... nope its 9:40 ... !! Take it you're an insomniac!!!
May 10 '07 #5
SammyB
807 Expert 512MB
4:30 ... nope its 9:40 ... !! Take it you're an insomniac!!!
Well, I'm going back to bed! Here's what I have. I think it would work except for the Type.Missing: can't figure out how to pass a missing Com int parameter:
Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Text;
  7. using System.Windows.Forms;
  8. using PowerPoint = Microsoft.Office.Interop.PowerPoint; // Add a reference to Microsoft.Office.Interop.PowerPoint.dll
  9. using Office = Microsoft.Office.Core; // Add a reference to office.dll
  10. namespace PowerPointCombine
  11. {
  12.     public partial class Form1 : Form
  13.     {
  14.         public Form1()
  15.         {
  16.             InitializeComponent();
  17.         }
  18.         private void button1_Click(object sender, EventArgs e)
  19.         {
  20.             openFileDialog1.Filter = "Presentations (*.ppt)|*.ppt|All files (*.*)|*.*";
  21.             openFileDialog1.FilterIndex = 1;
  22.             openFileDialog1.Multiselect = true;
  23.             openFileDialog1.Title = "Select Presentations To Merge";
  24.             openFileDialog1.ShowDialog();
  25.             // Create an instance of PowerPoint, make it visible, and open a new pres.
  26.             PowerPoint.ApplicationClass ppApp = new PowerPoint.ApplicationClass();
  27.             ppApp.Visible = Office.MsoTriState.msoTrue;
  28.             PowerPoint.Presentations ppSet = ppApp.Presentations;
  29.             PowerPoint.Presentation ppPres = ppSet.Add(Office.MsoTriState.msoTrue);
  30.             PowerPoint.Slides ppSlides = ppPres.Slides;
  31.             foreach (string f in openFileDialog1.FileNames)
  32.             {
  33.                 ppSlides.InsertFromFile(f, 1, ppSlides.Count, Type.Missing);
  34.             }
  35.             ppPres.SaveAs(@"C:\Documents and Settings\Sam\My Documents\Merged.ppt", PowerPoint.PpSaveAsFileType.ppSaveAsPresentation, Office.MsoTriState.msoFalse);
  36.             ppPres.Close();
  37.             System.Runtime.InteropServices.Marshal.ReleaseComObject(ppPres);
  38.             ppPres = null;
  39.             System.Runtime.InteropServices.Marshal.ReleaseComObject(ppSlides);
  40.             ppSlides = null;
  41.             System.Runtime.InteropServices.Marshal.ReleaseComObject(ppSet);
  42.             ppSet = null;
  43.             ppApp.Quit();
  44.             System.Runtime.InteropServices.Marshal.ReleaseComObject(ppApp);
  45.             ppApp = null;
  46.         }
  47.     }
  48. }
BTW, as you can see, you have to be very precise in C#. All of the Office Com stuff is wrapped in what VBA calls a variant which does not fly in C# so you cannot sling stuff together like Application.Presentations.Add.
May 10 '07 #6
SammyB
807 Expert 512MB
Well, so much for our "genius" solution. You cannot pass missing value parameters in C# (http://msdn2.microsoft.com/en-us/lib...ffice.11).aspx), so we will have to open each presentation manually.
May 10 '07 #7
Manually as in the user will have to open the files???
Not so good then ... wonder if there's another approach???
May 10 '07 #8
SammyB
807 Expert 512MB
Manually as in the user will have to open the files???
Not so good then ... wonder if there's another approach???
No, no, not that! We will have to open each presentation in code, copy the slides, switch back to the new presentation, and paste the slides there. Only 4 or 5 more lines. After simplifying a recorded macro, it looks like:
Expand|Select|Wrap|Line Numbers
  1. ActivePresentation.Slides.Range.Copy
  2. Windows.Item(Index:=2).Activate
  3. ActiveWindow.View.Paste
but there I already had two presentations open. I may have time tonight after you are sound asleep to do it in C#. This is my first venture with PowerPoint InterOp. Makes regular PoPo programming look easy. Stay tuned and/or try it yourself. If you try it yourself, you'll need to save a DocumentWindow object from the merged Presentation. I suspect that it is ppPres.Windows(1). Then you won't need the Activate, just an Open, Copy & Paste for each file.
May 10 '07 #9
SammyB
807 Expert 512MB
Well, it sort of works! It was very annoying. I have a new rule: NEVER do InterOp in C#: it should be called InterNoOp. Maybe you can make it better! If so, it would be great to post your code. HTH --Sam
Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Text;
  7. using System.Windows.Forms;
  8. using PowerPoint = Microsoft.Office.Interop.PowerPoint; // Add a reference to Microsoft.Office.Interop.PowerPoint.dll
  9. using Office = Microsoft.Office.Core; // Add a reference to office.dll
  10. namespace PowerPointCombine
  11. {
  12.     public partial class Form1 : Form
  13.     {
  14.         public Form1()
  15.         {
  16.             InitializeComponent();
  17.         }
  18.         private void button1_Click(object sender, EventArgs e)
  19.         {
  20.             openFileDialog1.Filter = "Presentations (*.ppt)|*.ppt|All files (*.*)|*.*";
  21.             openFileDialog1.FilterIndex = 1;
  22.             openFileDialog1.Multiselect = true;
  23.             openFileDialog1.Title = "Select Presentations To Merge";
  24.             openFileDialog1.ShowDialog();
  25.             // Create an instance of PowerPoint, make it visible, and open a new pres.
  26.             PowerPoint.ApplicationClass ppApp = new PowerPoint.ApplicationClass();
  27.             ppApp.Visible = Office.MsoTriState.msoTrue;
  28.             PowerPoint.Presentations ppSet = ppApp.Presentations;
  29.             PowerPoint.Presentation ppMergedPres = ppSet.Add(Office.MsoTriState.msoTrue);
  30.             PowerPoint.Slides ppMergedSlides = ppMergedPres.Slides;
  31.             PowerPoint.DocumentWindows ppWindows = ppMergedPres.Windows;
  32.             PowerPoint.DocumentWindow ppWindow = ppWindows[1];
  33.             PowerPoint.View ppMergedView = ppWindow.View;
  34.             PowerPoint.Presentation ppPres = null;
  35.             PowerPoint.Slides ppSlides = null;
  36.             foreach (string f in openFileDialog1.FileNames)
  37.             {
  38.                 //ppSlides.InsertFromFile(f, ppSlides.Count, 1, 999);
  39.                 ppPres = ppSet.Open(f, Office.MsoTriState.msoTrue, Office.MsoTriState.msoFalse, Office.MsoTriState.msoTrue);
  40.                 ppSlides = ppPres.Slides;
  41.                 for (int i=ppSlides.Count; i>=1; i--)
  42.                 {
  43.                     ppSlides[i].Copy();
  44.                     ppMergedView.Paste();
  45.                 }
  46.                 ppPres.Close();
  47.             }
  48.             ppMergedPres.SaveAs(@"C:\Documents and Settings\Sam\My Documents\Merged.ppt", PowerPoint.PpSaveAsFileType.ppSaveAsPresentation, Office.MsoTriState.msoFalse);
  49.             ppMergedPres.Close();
  50.             System.Runtime.InteropServices.Marshal.ReleaseComObject(ppMergedPres);
  51.             ppMergedPres = null;
  52.             System.Runtime.InteropServices.Marshal.ReleaseComObject(ppSlides);
  53.             ppSlides = null;
  54.             System.Runtime.InteropServices.Marshal.ReleaseComObject(ppSet);
  55.             ppSet = null;
  56.             ppApp.Quit();
  57.             System.Runtime.InteropServices.Marshal.ReleaseComObject(ppApp);
  58.             ppApp = null;
  59.         }
  60.     }
  61. }
May 11 '07 #10
Hi again ...
Got dragged into something else ... anyhow ... trying to find the references .. however they seem to be missing. There's no interop or core ...
Oh and I'm doing this on a web form?!?!
May 16 '07 #11
SammyB
807 Expert 512MB
Hi again ...
Got dragged into something else ... anyhow ... trying to find the references .. however they seem to be missing. There's no interop or core ...
Oh and I'm doing this on a web form?!?!
Why, Why, Why, etc

You have to download Interop. Have you done that?
If you have Visual Studio, then you follow the download instructions.
If you have Express, you just add the ref by browsing to the Interop directory.

When googling for info about this, I remember a lot of whining about Interop & web. Do you really need a Web form? If so, I'd do some google searches.

Do you have to do this in C#? VB would be easier. It allows missing value parameters, so the easy InsertFromFile would work. If you must do it in C#, then I think that it would be easier to just open each presentation, get the slide count, and close it. Then, again, you could use InsertFromFile.

Have you thought about how to order the presentations? Since XP, the OpenFileDialog does not have any order except insanity?

Aren't you glad you got dragged into something else? BTW, I don't do web, so I'll be no help. :) Sam
May 16 '07 #12
Thanks Sam ...

Got those reference's ... !

Currently I have the first bit (getting the files and ordering them) done in C# ... I just assumed since part of it was working that way the rest would be done in C# ....

The files are ordered in a listbox ... these I guess i'll need to pass as a collection to the function you've written above...

The function for getting and ordering the files are:

Expand|Select|Wrap|Line Numbers
  1. public partial class FullQuestionnaire : System.Web.UI.Page
  2. {
  3.     protected void Page_Load(object sender, EventArgs e)
  4.     {
  5.  
  6.     }
  7.  
  8.     protected void Blue(object sender, EventArgs e)
  9.     {
  10.         foreach(ListItem item in CheckBoxList1.Items)
  11.         {
  12.             if (item.Selected && !FileSelectedListBox.Items.Contains(item))
  13.             {
  14.                 FileSelectedListBox.Items.Add(new ListItem(item.Text, item.Value));
  15.             }
  16.             else if (!item.Selected && FileSelectedListBox.Items.Contains(item))
  17.             {
  18.                 FileSelectedListBox.Items.Remove(item);
  19.             }
  20.         }
  21.     }
  22.     protected void Button1_Click(object sender, EventArgs e)
  23.     {
  24.  
  25.     }
  26. }
  27.  
  28.  
  29.  
My first .NET app ... muddling through as you can see .. the something else I was pulled into wasn't that great!!!
May 16 '07 #13
Hiya,

From looking about i've got the following bit of code to get the ListBox Items into and arra to pass to your function ....

However, since i'm very new to C# this isn't making much sense to me.
For example, what does the <string> bit mean ... do I pass the name of the ListBox ... or is this a new variable?

Expand|Select|Wrap|Line Numbers
  1.  
  2. protected void SomeEvent(...)
  3. {
  4.    //get selected values
  5.    List<string> selected = new List<string>();
  6.    foreach(ListItem item in myControl.Items)
  7.    {
  8.         if(item.selected)
  9.         {
  10.             selected.Add(item.Value);
  11.         }
  12.    }
  13.    //call function
  14.    MyClass c = new MyClass(...);
  15.    c.MyFunction(selected.ToArray());
  16. }
  17.  
  18.  
  19.  
Thanks,
J

p.s. You wouldn't know of a good place to go brush up on my C#???!!!
May 17 '07 #14
Hi again ...

Figured out the array thing but am having a couple of issues with the way i'm passing in the file names:
I get the error:
The best overloaded method match for 'Microsoft.Office.Interop.PowerPoint.Presentations .Open(string, Microsoft.Office.Core.MsoTriState, Microsoft.Office.Core.MsoTriState, Microsoft.Office.Core.MsoTriState)' has some invalid arguments


This is the code that I've got now:

Expand|Select|Wrap|Line Numbers
  1.     protected void Button1_Click(object sender, EventArgs e)
  2.    // Create an instance of PowerPoint, make it visible, and open a new pres.
  3.         Microsoft.Office.Interop.PowerPoint.ApplicationClass ppApp = new Microsoft.Office.Interop.PowerPoint.ApplicationClass();
  4.         ppApp.Visible = Office.MsoTriState.msoTrue;
  5.         Powerpoint.Presentations ppSet = ppApp.Presentations;
  6.         Powerpoint.Presentation ppMergedPres = ppSet.Add(Office.MsoTriState.msoTrue);
  7.         Powerpoint.Slides ppMergedSlides = ppMergedPres.Slides;
  8.         Powerpoint.DocumentWindows ppWindows = ppMergedPres.Windows;
  9.         Powerpoint.DocumentWindow ppWindow = ppWindows[1];
  10.         Powerpoint.View ppMergedView = ppWindow.View;
  11.         Powerpoint.Presentation ppPres = null;
  12.         Powerpoint.Slides ppSlides = null;
  13.         System.Collections.Generic.List<String> selected = new System.Collections.Generic.List<String>();
  14.         foreach (ListItem item in FileSelectedListBox.Items)
  15.         {
  16.             if (item.Selected)
  17.             {
  18.                 selected.Add(item.Value);
  19.                 //ppSlides.InsertFromFile(f, ppSlides.Count, 1, 999);
  20.                 ppPres = ppSet.Open(selected, Office.MsoTriState.msoTrue, Office.MsoTriState.msoFalse, Office.MsoTriState.msoTrue);
  21.                 ppSlides = ppPres.Slides;
  22.                 for (int i = ppSlides.Count; i >= 1; i--)
  23.                 {
  24.                     ppSlides[i].Copy();
  25.                     ppMergedView.Paste();
  26.                 }
  27.                 ppPres.Close();
  28.             }
  29.         }
  30.  
  31.     }
  32.  
Thanks

J
May 18 '07 #15
SammyB
807 Expert 512MB
The first parameter of the Open must be a string. Also, probably easier to use ListBox::CheckedItems
Expand|Select|Wrap|Line Numbers
  1. foreach (object o in FileSelectedListBox.CheckedItems)
  2. {
  3.     ppPres = ppSet.Open(o.ToString(), Office.MsoTriState.msoTrue, Office.MsoTriState.msoFalse, Office.MsoTriState.msoTrue);
  4. }
  5.  
May 18 '07 #16
The first parameter of the Open must be a string. Also, probably easier to use ListBox::CheckedItems
Expand|Select|Wrap|Line Numbers
  1. foreach (object o in FileSelectedListBox.CheckedItems)
  2. {
  3.     ppPres = ppSet.Open(o.ToString(), Office.MsoTriState.msoTrue, Office.MsoTriState.msoFalse, Office.MsoTriState.msoTrue);
  4. }
  5.  
On the line
Expand|Select|Wrap|Line Numbers
  1. foreach (object o in FileSelectedListBox.CheckedItems)
  2.  
How do I get the items value (which is the file address) rather than just the file name (which is causing an error on Powerpoint because it can't find the file by just its name)??

Thanks

J
May 18 '07 #17
SammyB
807 Expert 512MB
I'm confused. CheckedListBox.Items[i] does not have a Value property. It is just the string that you see in the box. Guess this has something to do with ListItem in your code. What is ListItem?
May 18 '07 #18
So, a little tipe:
-> PowerPoint.Application ppApp = new PowerPoint.ApplicationClass();

It's perfect!
Expand|Select|Wrap|Line Numbers
  1.  
  2. using System;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Data;
  6. using System.Drawing;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using PowerPoint = Microsoft.Office.Interop.PowerPoint; // Add a reference to Microsoft.Office.Interop.PowerPoint.dll
  10. using Office = Microsoft.Office.Core; // Add a reference to office.dll
  11.  
  12. namespace PowerPointCombine
  13. {
  14. public partial class MainForm : Form
  15. {
  16.  
  17. public MainForm()
  18. {
  19. InitializeComponent();
  20. }
  21.  
  22. private void button1_Click(object sender, EventArgs e)
  23. {
  24. openFileDialog1.Filter = "Presentations (*.ppt)|*.ppt|All files (*.*)|*.*";
  25. openFileDialog1.FilterIndex = 1;
  26. openFileDialog1.Multiselect = true;
  27. openFileDialog1.Title = "Select Presentations To Merge";
  28. openFileDialog1.ShowDialog();
  29. // Create an instance of PowerPoint, make it visible, and open a new pres.
  30.  
  31. PowerPoint.Application ppApp = new PowerPoint.ApplicationClass();
  32. //ppApp.Visible = Office.MsoTriState.msoTrue;
  33. PowerPoint.Presentations ppSet = ppApp.Presentations;
  34. PowerPoint.Presentation ppMergedPres = ppSet.Add(Office.MsoTriState.msoTrue);
  35. PowerPoint.Slides ppMergedSlides = ppMergedPres.Slides;
  36. PowerPoint.Presentation ppPres = null;
  37. foreach (string f in openFileDialog1.FileNames)
  38. {
  39.     ppPres = ppSet.Open(f, Office.MsoTriState.msoTrue, Office.MsoTriState.msoFalse, Office.MsoTriState.msoFalse);
  40.          ppMergedSlides.InsertFromFile(f, ppMergedSlides.Count, 1, ppPres.Slides.Count);
  41.      ppPres.Close(); 
  42. }
  43. ppMergedPres.SaveAs(@"C:\Merged.ppt", PowerPoint.PpSaveAsFileType.ppSaveAsPresentation, Office.MsoTriState.msoFalse);
  44. ppMergedPres.Close();
  45. System.Runtime.InteropServices.Marshal.ReleaseComObject(ppMergedPres);
  46. ppMergedPres = null;
  47. System.Runtime.InteropServices.Marshal.ReleaseComObject(ppSet);
  48. ppSet = null;
  49. ppApp.Quit(); 
  50. System.Runtime.InteropServices.Marshal.ReleaseComObject(ppApp);
  51. ppApp = null;
  52. }
  53. }
  54.  
May 19 '07 #19
Hi ...

Just replacing the opendialogue with the code below ... so user can select from a set group of presentations ... other than that your code is perfect for what I'm trying to do. The ListItem is CheckBoxList1 :

Expand|Select|Wrap|Line Numbers
  1.     protected void Blue(object sender, EventArgs e)
  2.     {
  3.         foreach(ListItem item in CheckBoxList1.Items)
  4.         {
  5.             if (item.Selected && !FileSelectedListBox.Items.Contains(item))
  6.             {
  7.                 FileSelectedListBox.Items.Add(new ListItem(item.Text, item.Value));
  8.             }
  9.             else if (!item.Selected && FileSelectedListBox.Items.Contains(item))
  10.             {
  11.                 FileSelectedListBox.Items.Remove(item);
  12.             }
  13.         }
  14.     }
  15.  
Thanks

J
May 21 '07 #20
SammyB
807 Expert 512MB
Hi ...

The ListItem is CheckBoxList1 :

J
I forgot that you are doing a web app, so I guess the properties are different. Glad it works!
May 22 '07 #21
I forgot that you are doing a web app, so I guess the properties are different. Glad it works!
It's not working at the minute ... I can't seem to pass the values of the list of Items in the FileSelectedListBox, into your foreach loop:
Expand|Select|Wrap|Line Numbers
  1. foreach (string f in openFileDialog1.FileNames)
  2.  
Do you know how I can pass this??

Thanks again

J
May 22 '07 #22
It's all OK I realised what I was doing wrong I just need to pass this:

Expand|Select|Wrap|Line Numbers
  1. foreach (ListItem o in FileSelectedListBox.Items)
  2.  
Right let me get onto the rest of it .... :(

J
May 22 '07 #23
Hi ...

Got the above working a treat!! Thanks very much ...
Is it possible to put text box values into the first slide of the presentation that is going to contain the merged powerpoint files?

Been trawling the web and I can't find anything relating to this?

Thanks

J
May 22 '07 #24
I do have something now which is as follows:

Expand|Select|Wrap|Line Numbers
  1.         Powerpoint._Slide objSlide;
  2.         Powerpoint.TextRange objTextRng = null;
  3.         //ppApp.PresentationNewSlide
  4.         objSlide = ppPres.Slides.Add(1, Powerpoint.PpSlideLayout.ppLayoutBlank);
  5.         //objSlide = ppSlides.Add(1, Powerpoint.PpSlideLayout.ppLayoutText);
  6.         objTextRng = objSlide.Shapes[1].TextFrame.TextRange;
  7.         objTextRng.Text = "My Presentation";
  8.  
  9.  
But its causing the "New" Keyword is needed on the following line but I can't see where to add this ... can you see what I'm missing?

Expand|Select|Wrap|Line Numbers
  1.         objSlide = ppPres.Slides.Add(1, Powerpoint.PpSlideLayout.ppLayoutBlank);
  2.  
Thanks so much

J
May 22 '07 #25
SammyB
807 Expert 512MB
No Interop here, but your code looks good to me. Best I can do right now is write a macro which looks just like your code. I'll try it in C# tonight.
Expand|Select|Wrap|Line Numbers
  1. Dim ppPres As PowerPoint.Presentation
  2. Set ppPres = ActivePresentation
  3. Dim ppSlide As PowerPoint.Slide
  4. Set ppSlide = ppPres.Slides.Add(1, ppLayoutText)
  5. ppSlide.Shapes(1).TextFrame.TextRange.Text = "Help"
  6. ppSlide.Shapes(2).TextFrame.TextRange.Text = "Me"
  7.  
May 22 '07 #26
SammyB
807 Expert 512MB
You probably have to create a Slides object (line 5). This worked for me:
Expand|Select|Wrap|Line Numbers
  1. PowerPoint.ApplicationClass ppApp = new PowerPoint.ApplicationClass();
  2. ppApp.Visible = Office.MsoTriState.msoTrue;
  3. PowerPoint.Presentations ppSet = ppApp.Presentations;
  4. PowerPoint.Presentation ppPres = ppSet.Add(Office.MsoTriState.msoTrue);
  5. PowerPoint.Slides ppSlides = ppPres.Slides;
  6. PowerPoint.Slide ppSlide = ppSlides.Add(1, PowerPoint.PpSlideLayout.ppLayoutText);
  7. ppSlide.Shapes[1].TextFrame.TextRange.Text = "Sample Slide";
  8. ppSlide.Shapes[2].TextFrame.TextRange.Text = "Bullet One" + System.Environment.NewLine + "Bullet Two";
  9.  
  10.  
May 23 '07 #27
Hi ...

It's working though, the merged files bit is opening another presentation file and adding the merged files to that ... how do I get the merged files to follow on from the automatically entered text?
May 23 '07 #28
SammyB
807 Expert 512MB
Hi ...

It's working though, the merged files bit is opening another presentation file and adding the merged files to that ... how do I get the merged files to follow on from the automatically entered text?
In our code snippets, we've used ppSlides in two different ways, as the new presentation (line 5 in #27 above), and as the old presentation (line 21 in #15 above). You just need to identify all of your PP references and make sure that they are named properly. Maybe easiest to replace ppMergedObject with newObject (newPres, newSlides, newSlide) and ppObject with oldObject (oldPres, oldSlides). Also, you should use ewertonrp's #19 above, so that you can use the InsertFromFile (line 39).
Are we confused yet?
May 23 '07 #29
Are we confused yet?
Errrrr yeah confused - how did you know???
May 23 '07 #30
SammyB
807 Expert 512MB
Errrrr yeah confused - how did you know???
That's why we get paid the big bucks!
May 23 '07 #31
This is as far as I got ... the addition of the extra slide just isn't working ... can you see what i'm missing....???

Expand|Select|Wrap|Line Numbers
  1.         Powerpoint.ApplicationClass ppApp = new Powerpoint.ApplicationClass();
  2.         ppApp.Visible = Office.MsoTriState.msoTrue;
  3.         Powerpoint.Presentations ppSet = ppApp.Presentations;
  4.         Powerpoint.Presentation ppMergedPres = ppSet.Add(Office.MsoTriState.msoTrue);
  5.         Powerpoint.Slides ppMergedSlides = ppMergedPres.Slides;
  6.         Powerpoint.DocumentWindows ppWindows = ppMergedPres.Windows;
  7.         Powerpoint.DocumentWindow ppWindow = ppWindows[1];
  8.         Powerpoint.View ppMergedView = ppWindow.View;
  9.         Powerpoint.Presentation ppPres = ppSet.Add(Office.MsoTriState.msoTrue);
  10.         Powerpoint.Slides ppSlides = ppPres.Slides;
  11.         Powerpoint.Slide ppSlide = ppSlides.Add(1, Powerpoint.PpSlideLayout.ppLayoutText);
  12.         System.Collections.Generic.List<String> selected = new System.Collections.Generic.List<String>();
  13.         foreach (ListItem o in FileSelectedListBox.Items)
  14.         {
  15.  
  16.                 //ppSlides.InsertFromFile(o, ppSlides.Count, 1, 999);
  17.             ppPres = ppSet.Open(o.Value.ToString(), Office.MsoTriState.msoTrue, Office.MsoTriState.msoFalse, Office.MsoTriState.msoTrue);
  18.             ppSlides = ppPres.Slides;
  19.             for (int i = ppSlides.Count; i >= 1; i--)
  20.             {
  21.                 ppSlides[i].Copy();
  22.                 ppMergedView.Paste();
  23.             }
  24.             ppPres.Close();
  25.         }
  26.  
  27.         //ppSlides = ppPres.Slides;
  28.         ppSlides.Add(1, Powerpoint.PpSlideLayout.ppLayoutText); 
  29.         ppSlide.Shapes[1].TextFrame.TextRange.Text = "Questionnaire";
  30.         ppSlide.Shapes[2].TextFrame.TextRange.Text = relManNameTextBox.Text;
  31.  
  32.         string sFileName = System.IO.Path.ChangeExtension(System.IO.Path.GetRandomFileName(), "ppt");
  33.         ppMergedPres.SaveAs(@"V:\projects\JG\PitchBook\PitchBook\Presentations\Built\" + sFileName, Powerpoint.PpSaveAsFileType.ppSaveAsPresentation, Office.MsoTriState.msoFalse);
  34.         ppMergedPres.Close();
  35.         System.Runtime.InteropServices.Marshal.ReleaseComObject(ppMergedPres);
  36.         ppMergedPres = null;
  37.         System.Runtime.InteropServices.Marshal.ReleaseComObject(ppSlides);
  38.         ppSlides = null;
  39.         ppApp.Quit();
  40.         System.Runtime.InteropServices.Marshal.ReleaseComObject(ppSet);
  41.         ppSet = null;
  42.         System.Runtime.InteropServices.Marshal.ReleaseComObject(ppApp);
  43.         ppApp = null;
  44.  
May 23 '07 #32
SammyB
807 Expert 512MB
All of your ppSlides.Add should be ppMergedSlides.Add
May 23 '07 #33
I've posted a solution in javascript here: http://code.google.com/p/powerpointjoin/
Sep 15 '08 #34
Hi Guys, that Code for Merging Single Slides works perfect for me! But one Problem! My single Slides do have a Template( Background, Font, etc...)...

When i merge the Slides the merge.ppt dont have this Template! How can i fix this?
Dec 4 '09 #35
How about a solution for Mac users? I have a similar situation where I need to combine multiple slides from different presentations into one presentation. Ideally, I'd like to keep the formatting in tact.

Looking for a solution on this...thanks.
Jul 29 '10 #36

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by mheydman | last post: by
1 post views Thread by Ryan | last post: by
reply views Thread by Marc Eggenberger | last post: by
1 post views Thread by barry | last post: by
1 post views Thread by chrizstone | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.