using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.Office.Interop.PowerPoint;
using Microsoft.Office.Core;
using System.Reflection;
using System.IO;
using System.Diagnostics;
using System.Threading;private void RunPPT(string strDir, string strMac)
{
Microsoft.Office.Interop.PowerPoint.ApplicationClass oPP = new Microsoft.Office.Interop.PowerPoint.ApplicationClass(); oPP.Visible = MsoTriState.msoTrue;
Microsoft.Office.Interop.PowerPoint.Presentations oPresSet = oPP.Presentations; Microsoft.Office.Interop.PowerPoint._Presentation oPres = oPresSet.Open(@strDir,
MsoTriState.msoFalse, MsoTriState.msoFalse,
MsoTriState.msoTrue); //注意此处的宏名需要加上文件名
//解析出目录文件中的文件名
int tempPos = strDir.LastIndexOf(@"\");
string singleFileName = strDir.Substring(tempPos+1, strDir.Length-tempPos-1); string tmpMacroName = "'" + singleFileName + "'!" + strMac;
RunMacro(oPP, new Object[] { tmpMacroName }); oPres.Close();
System.Runtime.InteropServices.Marshal.ReleaseComObject(oPres);
oPres = null;
System.Runtime.InteropServices.Marshal.ReleaseComObject(oPresSet);
oPresSet = null;
oPP.Quit();
System.Runtime.InteropServices.Marshal.ReleaseComObject(oPP);
oPP = null; GC.Collect();}/// <summary>
/// 本程序专门用于运行宏
/// </summary>
/// <param name="oApp"></param>
/// <param name="oRunArgs"></param>
private void RunMacro(object oApp, object[] oRunArgs)
{
oApp.GetType().InvokeMember("Run",
System.Reflection.BindingFlags.Default |
System.Reflection.BindingFlags.InvokeMethod,
null, oApp, oRunArgs);
}这是我原来写的一个调用PowerPoint文档中的VBA宏的一个程式,是从微软的网站上拷的源代码。可以用一下。你可以看一下。。需要看详细的请到
http://support.microsoft.com/kb/306683/zh-cn希望能帮到你。
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.Office.Interop.PowerPoint;
using Microsoft.Office.Core;
using System.Reflection;
using System.IO;
using System.Diagnostics;
using System.Threading;private void RunPPT(string strDir, string strMac)
{
Microsoft.Office.Interop.PowerPoint.ApplicationClass oPP = new Microsoft.Office.Interop.PowerPoint.ApplicationClass(); oPP.Visible = MsoTriState.msoTrue;
Microsoft.Office.Interop.PowerPoint.Presentations oPresSet = oPP.Presentations; Microsoft.Office.Interop.PowerPoint._Presentation oPres = oPresSet.Open(@strDir,
MsoTriState.msoFalse, MsoTriState.msoFalse,
MsoTriState.msoTrue); //注意此处的宏名需要加上文件名
//解析出目录文件中的文件名
int tempPos = strDir.LastIndexOf(@"\");
string singleFileName = strDir.Substring(tempPos+1, strDir.Length-tempPos-1); string tmpMacroName = "'" + singleFileName + "'!" + strMac;
RunMacro(oPP, new Object[] { tmpMacroName }); oPres.Close();
System.Runtime.InteropServices.Marshal.ReleaseComObject(oPres);
oPres = null;
System.Runtime.InteropServices.Marshal.ReleaseComObject(oPresSet);
oPresSet = null;
oPP.Quit();
System.Runtime.InteropServices.Marshal.ReleaseComObject(oPP);
oPP = null; GC.Collect();}/// <summary>
/// 本程序专门用于运行宏
/// </summary>
/// <param name="oApp"></param>
/// <param name="oRunArgs"></param>
private void RunMacro(object oApp, object[] oRunArgs)
{
oApp.GetType().InvokeMember("Run",
System.Reflection.BindingFlags.Default |
System.Reflection.BindingFlags.InvokeMethod,
null, oApp, oRunArgs);
}这是我原来写的一个调用PowerPoint文档中的VBA宏的一个程式,是从微软的网站上拷的源代码。可以用一下。你可以看一下。。需要看详细的请到
http://support.microsoft.com/kb/306683/zh-cn希望能帮到你。
不需要装什么,但你肯定是要装office的吧,我这边装的是office 2003,
你在com组件里面找到这个就是了:Microsoft PowerPoint 11.0 object library