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: -
using PowerPoint = Microsoft.Office.Interop.PowerPoint;
-
//Maybe the following: -
PowerPoint.Application oPPT;
-
PowerPoint.Presentations objPresSet;
-
//the location of your powerpoint presentation -
string strPres;
-
strPres = @"mpPres.ppt";
-
But have no idea where to go from here ...
Any help would be very much appreciated ..
Thanks
J
35 13680 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
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: -
Sub Macro6()
-
-
Dim PPApp As PowerPoint.Application
-
Dim PPPres As PowerPoint.Presentation
-
Dim PPSlide As PowerPoint.Slide
-
-
' Create instance of PowerPoint
-
Set PPApp = CreateObject("Powerpoint.Application")
-
-
' Create a presentation
-
Set PPPres = PPApp.Presentations.Add
-
-
-
Dim nSlides As Integer
-
Dim fnames As New Collection
-
fnames.Add "Blah1.ppt"
-
fnames.Add "Blah2.ppt"
-
'fnames.Add "p3.ppt"
-
'fnames.Add "p4.ppt"
-
'fnames.Add "p5.ppt"
-
For Each fnam In fnames
-
nSlides = ActivePresentation.Slides.InsertFromFile(fnam, ActivePresentation.Slides.Count)
-
Next
-
End Sub
-
-
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! :)
4:30 ... nope its 9:40 ... !! Take it you're an insomniac!!!
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: - using System;
-
using System.Collections.Generic;
-
using System.ComponentModel;
-
using System.Data;
-
using System.Drawing;
-
using System.Text;
-
using System.Windows.Forms;
-
using PowerPoint = Microsoft.Office.Interop.PowerPoint; // Add a reference to Microsoft.Office.Interop.PowerPoint.dll
-
using Office = Microsoft.Office.Core; // Add a reference to office.dll
-
namespace PowerPointCombine
-
{
-
public partial class Form1 : Form
-
{
-
public Form1()
-
{
-
InitializeComponent();
-
}
-
private void button1_Click(object sender, EventArgs e)
-
{
-
openFileDialog1.Filter = "Presentations (*.ppt)|*.ppt|All files (*.*)|*.*";
-
openFileDialog1.FilterIndex = 1;
-
openFileDialog1.Multiselect = true;
-
openFileDialog1.Title = "Select Presentations To Merge";
-
openFileDialog1.ShowDialog();
-
// Create an instance of PowerPoint, make it visible, and open a new pres.
-
PowerPoint.ApplicationClass ppApp = new PowerPoint.ApplicationClass();
-
ppApp.Visible = Office.MsoTriState.msoTrue;
-
PowerPoint.Presentations ppSet = ppApp.Presentations;
-
PowerPoint.Presentation ppPres = ppSet.Add(Office.MsoTriState.msoTrue);
-
PowerPoint.Slides ppSlides = ppPres.Slides;
-
foreach (string f in openFileDialog1.FileNames)
-
{
-
ppSlides.InsertFromFile(f, 1, ppSlides.Count, Type.Missing);
-
}
-
ppPres.SaveAs(@"C:\Documents and Settings\Sam\My Documents\Merged.ppt", PowerPoint.PpSaveAsFileType.ppSaveAsPresentation, Office.MsoTriState.msoFalse);
-
ppPres.Close();
-
System.Runtime.InteropServices.Marshal.ReleaseComObject(ppPres);
-
ppPres = null;
-
System.Runtime.InteropServices.Marshal.ReleaseComObject(ppSlides);
-
ppSlides = null;
-
System.Runtime.InteropServices.Marshal.ReleaseComObject(ppSet);
-
ppSet = null;
-
ppApp.Quit();
-
System.Runtime.InteropServices.Marshal.ReleaseComObject(ppApp);
-
ppApp = null;
-
}
-
}
-
}
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.
Manually as in the user will have to open the files???
Not so good then ... wonder if there's another approach???
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: - ActivePresentation.Slides.Range.Copy
-
Windows.Item(Index:=2).Activate
-
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.
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 - using System;
-
using System.Collections.Generic;
-
using System.ComponentModel;
-
using System.Data;
-
using System.Drawing;
-
using System.Text;
-
using System.Windows.Forms;
-
using PowerPoint = Microsoft.Office.Interop.PowerPoint; // Add a reference to Microsoft.Office.Interop.PowerPoint.dll
-
using Office = Microsoft.Office.Core; // Add a reference to office.dll
-
namespace PowerPointCombine
-
{
-
public partial class Form1 : Form
-
{
-
public Form1()
-
{
-
InitializeComponent();
-
}
-
private void button1_Click(object sender, EventArgs e)
-
{
-
openFileDialog1.Filter = "Presentations (*.ppt)|*.ppt|All files (*.*)|*.*";
-
openFileDialog1.FilterIndex = 1;
-
openFileDialog1.Multiselect = true;
-
openFileDialog1.Title = "Select Presentations To Merge";
-
openFileDialog1.ShowDialog();
-
// Create an instance of PowerPoint, make it visible, and open a new pres.
-
PowerPoint.ApplicationClass ppApp = new PowerPoint.ApplicationClass();
-
ppApp.Visible = Office.MsoTriState.msoTrue;
-
PowerPoint.Presentations ppSet = ppApp.Presentations;
-
PowerPoint.Presentation ppMergedPres = ppSet.Add(Office.MsoTriState.msoTrue);
-
PowerPoint.Slides ppMergedSlides = ppMergedPres.Slides;
-
PowerPoint.DocumentWindows ppWindows = ppMergedPres.Windows;
-
PowerPoint.DocumentWindow ppWindow = ppWindows[1];
-
PowerPoint.View ppMergedView = ppWindow.View;
-
PowerPoint.Presentation ppPres = null;
-
PowerPoint.Slides ppSlides = null;
-
foreach (string f in openFileDialog1.FileNames)
-
{
-
//ppSlides.InsertFromFile(f, ppSlides.Count, 1, 999);
-
ppPres = ppSet.Open(f, Office.MsoTriState.msoTrue, Office.MsoTriState.msoFalse, Office.MsoTriState.msoTrue);
-
ppSlides = ppPres.Slides;
-
for (int i=ppSlides.Count; i>=1; i--)
-
{
-
ppSlides[i].Copy();
-
ppMergedView.Paste();
-
}
-
ppPres.Close();
-
}
-
ppMergedPres.SaveAs(@"C:\Documents and Settings\Sam\My Documents\Merged.ppt", PowerPoint.PpSaveAsFileType.ppSaveAsPresentation, Office.MsoTriState.msoFalse);
-
ppMergedPres.Close();
-
System.Runtime.InteropServices.Marshal.ReleaseComObject(ppMergedPres);
-
ppMergedPres = null;
-
System.Runtime.InteropServices.Marshal.ReleaseComObject(ppSlides);
-
ppSlides = null;
-
System.Runtime.InteropServices.Marshal.ReleaseComObject(ppSet);
-
ppSet = null;
-
ppApp.Quit();
-
System.Runtime.InteropServices.Marshal.ReleaseComObject(ppApp);
-
ppApp = null;
-
}
-
}
-
}
Sign in to post your reply or Sign up for a free account.
Similar topics |
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,...
|
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"...
|
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
|
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...
|
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...
| |
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
|
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)
|
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()
|
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();
|
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...
|
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,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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...
|
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,...
|
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();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |