473,898 Members | 2,455 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Merge Powerpoint presentations

19 New Member
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 13722
SammyB
807 Recognized Expert Contributor
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
gill1978
19 New Member
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 Recognized Expert Contributor
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
gill1978
19 New Member
4:30 ... nope its 9:40 ... !! Take it you're an insomniac!!!
May 10 '07 #5
SammyB
807 Recognized Expert Contributor
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.Pre sentations.Add.
May 10 '07 #6
SammyB
807 Recognized Expert Contributor
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
gill1978
19 New Member
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 Recognized Expert Contributor
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 Recognized Expert Contributor
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

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

Similar topics

2
2974
by: mheydman | last post by:
I hope I'm posting this in the right place... We are planning a website to be written in PHP (hopefully). One section of the site will offer powerpoint slide presentations for download. Are there any PHP-related tools/utils/code/3rd-party stuff that can facilitate the dynamic assembly of ppt presentations from single slide presentations- in other words, we want to allow the user to pick and choose which slides they are interested in,...
1
2245
by: Bret | last post by:
To provide a small team assistance in a rather massive data conversion effort, I've built an ASP script that scans/scrapes a pile of PowerPoint presentations that are in an agreed-upon format and pulls in textual data from these files to be uploaded into a database Believe it or not, the thing is (a) working, and (b) not too strange However, it only works for me (a member of the web server's administrators group). When one of the "normal"...
1
6360
by: Ryan | last post by:
PowerPoint.Application cannot open PPT file I am trying to use the following code using to open a PPT file using VS.NET 2003 and PowerPoint 2003 Option Strict Off Imports System.Runtime.InteropServices Imports Microsoft.Office.Interop Imports Microsoft.Office.Interop.PowerPoint Imports Microsoft.Office.Core Imports Microsoft.Office.Core.MsoControlType
0
568
by: Ata | last post by:
Hello, I am trying to copy the contents of the output of SQL Reporting Services to a PowerPoint slide. For this, I am using SQL Reporting Services to obtain an IMAGE stream, which I paste to the Windows clipboard. Then, using automation, I am trying to copy this information from the clipboard to a PowerPoint slide. However, I get an error at slide.Shapes.PasteSpecial. I am able create a System.Drawing.Bitmap object from the memory...
4
42170
by: Joseph | last post by:
I am trying to open a 3 powerpoint presentation simultaneously afte each other without interruption, the operator of the application doe not need to notice anything or interfere in the operation of th transition between the 3 presentations. Let us say I have three powerpoint presentation Presentation 1 Presentation 2, and Presentation 3. I like to fire them from a window form on the click event of a butto on the form. The sequence of...
0
2562
by: Marc Eggenberger | last post by:
Hi there. I have an webapp (asp.net) which should use powerpoint to create a presentation and then send that presentation to the user. I'm using VS2003 and Office2003 (project req.). The webapp runs find but when I try to open powerpoint in my asp.net code I get an error
1
2517
by: barry | last post by:
This is the code I am trying to execute in the page load Dim oapp As PowerPoint.Application oapp = New PowerPoint.Application oapp.Presentations.Open("C:\Inetpub\wwwroot\StoryBooks\AccessorMutator.ppt") The following error was given when executed System.Runtime.InteropServices.COMException: Presentations (unknown member)
8
7087
by: Rut | last post by:
Does anyone know how to start powerpoint from vb.net without the ppt screen appearing. I want to keep it hidden? Using this code: Try pp = New PowerPoint.Application pp.Visible = Office.MsoTriState.msoTrue pp.WindowState = PowerPoint.PpWindowState.ppWindowMinimized Application.DoEvents()
1
11921
by: chrizstone | last post by:
Hi Guys, What i want to do is: I want to create a Slide programmatically where a Table is on it! Here´s my Code: String strTemplate; strTemplate = template; String tableSlide = @"C:\Temp\TableSlide_" + guid.ToString();
0
9993
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9842
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10858
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10952
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
8036
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7189
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5882
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
6078
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3308
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.