PowerPoint 2010 adds a series of new Application-level events. Unfortunately, PowerPoint still makes it exceedingly difficult to trap and handle application-level events, so the simplest solution is to create a managed add-in to demonstrate the new events.
To see the events in action, follow these steps:
1. In Visual Studio 2010, create a new PowerPoint 2010 add-in project (use the video here to help you get started: http://msdn.microsoft.com/en-us/vsto/cc338006).
2. (C# only) In the ThisAddIn.cs class, in the ThisAddIn_Startup method, add the following code:
// C#:
Application.PresentationBeforeClose += new PowerPoint.EApplication_PresentationBeforeCloseEventHandler(Application_PresentationBeforeClose);
Application.PresentationCloseFinal += new PowerPoint.EApplication_PresentationCloseFinalEventHandler(Application_PresentationCloseFinal);
Application.ProtectedViewWindowActivate += new PowerPoint.EApplication_ProtectedViewWindowActivateEventHandler(Application_ProtectedViewWindowActivate);
Application.ProtectedViewWindowBeforeClose += new PowerPoint.EApplication_ProtectedViewWindowBeforeCloseEventHandler(Application_ProtectedViewWindowBeforeClose);
Application.ProtectedViewWindowBeforeEdit += new PowerPoint.EApplication_ProtectedViewWindowBeforeEditEventHandler(Application_ProtectedViewWindowBeforeEdit);
Application.ProtectedViewWindowDeactivate += new PowerPoint.EApplication_ProtectedViewWindowDeactivateEventHandler(Application_ProtectedViewWindowDeactivate);
Application.ProtectedViewWindowOpen += new PowerPoint.EApplication_ProtectedViewWindowOpenEventHandler(Application_ProtectedViewWindowOpen);
3. In the ThisAddIn.vb or ThisAddIn.cs class, add the following statements at the top of the file:
' Visual Basic:
Imports System.Windows.Forms
Imports Microsoft.Office.Interop.PowerPoint
// C#:
using System.Windows.Forms;
using Microsoft.Office.Interop.PowerPoint;
4. In the ThisAddIn.vb or ThisAddIn.cs class, add the following code, which traps and displays information about each of the new Application-level events:
' Visual Basic:
Private Sub Application_PresentationBeforeClose(
ByVal Pres As Presentation, ByRef Cancel As Boolean) _
Handles Application.PresentationBeforeClose
Cancel = (MessageBox.Show("PresentationBeforeClose", "Event",
MessageBoxButtons.OKCancel) = DialogResult.Cancel)
End Sub
Private Sub Application_PresentationCloseFinal(
ByVal Pres As Presentation) Handles Application.PresentationCloseFinal
MessageBox.Show("PresentationCloseFinal", "Event")
End Sub
Private Sub Application_ProtectedViewWindowActivate(
ByVal ProtViewWindow As ProtectedViewWindow) Handles Application.ProtectedViewWindowActivate
MessageBox.Show("ProtectedViewWindowActivate: " & ProtViewWindow.Caption, "Event")
End Sub
Private Sub Application_ProtectedViewWindowBeforeClose(
ByVal ProtViewWindow As ProtectedViewWindow,
ByVal ProtectedViewCloseReason As PpProtectedViewCloseReason,
ByRef Cancel As Boolean) Handles Application.ProtectedViewWindowBeforeClose
Dim reason As String = "none"
Select Case ProtectedViewCloseReason
Case PowerPoint.PpProtectedViewCloseReason.ppProtectedViewCloseEdit
reason = "Edit"
Case PowerPoint.PpProtectedViewCloseReason.ppProtectedViewCloseForced
reason = "Forced"
Case PowerPoint.PpProtectedViewCloseReason.ppProtectedViewCloseNormal
reason = "Normal"
End Select
Cancel = (MessageBox.Show(String.Format("ProtectedViewWindowBeforeClose: {0} ({1})",
ProtViewWindow.Caption, reason), "Event", MessageBoxButtons.OKCancel) = DialogResult.Cancel)
End Sub
Private Sub Application_ProtectedViewWindowBeforeEdit(
ByVal ProtViewWindow As ProtectedViewWindow,
ByRef Cancel As Boolean) Handles Application.ProtectedViewWindowBeforeEdit
Cancel = (MessageBox.Show("ProtectedViewWindowBeforeEdit" & ProtViewWindow.Caption,
"Event", MessageBoxButtons.OKCancel) = DialogResult.Cancel)
End Sub
Private Sub Application_ProtectedViewWindowDeactivate(
ByVal ProtViewWindow As ProtectedViewWindow) Handles Application.ProtectedViewWindowDeactivate
MessageBox.Show("ProtectedViewWindowDeactivate" & ProtViewWindow.Caption, "Event")
End Sub
Private Sub Application_ProtectedViewWindowOpen(
ByVal ProtViewWindow As ProtectedViewWindow) Handles Application.ProtectedViewWindowOpen
MessageBox.Show("ProtectedViewWindowOpen" & ProtViewWindow.Caption, "Event")
End Sub
// C#:
void Application_ProtectedViewWindowOpen(PowerPoint.ProtectedViewWindow ProtViewWindow)
{
MessageBox.Show("ProtectedViewWindowOpen: " + ProtViewWindow.Caption, "Event");
}
void Application_ProtectedViewWindowDeactivate(PowerPoint.ProtectedViewWindow ProtViewWindow)
{
MessageBox.Show("ProtectedViewWindowDeactivate: " + ProtViewWindow.Caption, "Event");
}
void Application_ProtectedViewWindowBeforeEdit(PowerPoint.ProtectedViewWindow ProtViewWindow, ref bool Cancel)
{
Cancel = (MessageBox.Show("ProtectedViewWindowBeforeEdit: " + ProtViewWindow.Caption,
"Event", MessageBoxButtons.OKCancel) == DialogResult.Cancel);
}
void Application_ProtectedViewWindowBeforeClose(PowerPoint.ProtectedViewWindow ProtViewWindow, PowerPoint.PpProtectedViewCloseReason ProtectedViewCloseReason, ref bool Cancel)
{
string reason = "none";
switch(ProtectedViewCloseReason)
{
case PpProtectedViewCloseReason.ppProtectedViewCloseEdit:
reason = "Edit";
break;
case PpProtectedViewCloseReason.ppProtectedViewCloseForced:
reason = "Forced";
break;
case PpProtectedViewCloseReason.ppProtectedViewCloseNormal:
reason = "Normal";
break;
}
Cancel = (MessageBox.Show(String.Format("ProtectedViewWindowBeforeClose: {0} ({1})",
ProtViewWindow.Caption, reason), "Event", MessageBoxButtons.OKCancel) == DialogResult.Cancel);
}
void Application_ProtectedViewWindowActivate(PowerPoint.ProtectedViewWindow ProtViewWindow)
{
MessageBox.Show("ProtectedViewWindowActivate: " + ProtViewWindow.Caption, "Event");
}
void Application_PresentationCloseFinal(PowerPoint.Presentation Pres)
{
MessageBox.Show("PresentationCloseFinal", "Event");
}
void Application_PresentationBeforeClose(PowerPoint.Presentation Pres, ref bool Cancel)
{
Cancel = (MessageBox.Show("PresentationBeforeClose", "Event",
MessageBoxButtons.OKCancel) == DialogResult.Cancel);
}
5. Run the sample add-in, which starts PowerPoint for you.
6. In PowerPoint, select File and then Open. In the Open dialog box, locate an existing PowerPoint presentation, but don't open it yet. Click the arrow next to the Open button, and select Open in Protected View from the menu (this opens the presentation in Protected View--most of the new events deal with Protected View).
7. With the presentation open in Protected View, note the ProtectedViewWindowOpen and then ProtectedViewWindowActivate events that occur.
8. Click the Enable Editing button above the design window, and note that you can cancel the ProtectedViewWindowBeforeEdit event. Click the Cancel button, verify that you don't go into edit mode, and try again, this time clicking OK. Note the ProtectedViewWindowBeforeClose and ProtectedViewWindowDeactivate events.
9. From the menu, select File and then Close. Note the cancellable PresentationBeforeClose event, and then the PresentationCloseFinal events.
10. Quit PowerPoint to return to Vi
没有合适的资源?快使用搜索试试~ 我知道了~
office2010 PowerPoint VBA / VB 范例大全

共24个文件
txt:24个


温馨提示
PPT.AddMedia.txt PPT.ApplyTheme.BackgroundStyle.txt PPT.ColorFormat.Brightness.txt PPT.ConvertTextToSmartArt.txt PPT.CreateVideo.txt PPT.CustomerDataDemo.txt PPT.GlowAndReflection.txt PPT.InteractWithChartLocation.txt PPT.MediaFormatProperties.txt PPT.MergeWithBaseline.txt PPT.NewEvents.txt PPT.PickupAndApplyAnimation.txt PPT.PublishSlides.txt PPT.ResampleMedia.txt PPT.RetrieveInformationAboutMediaControls.txt PPT.Shadow.txt PPT.ShapeTexture.txt PPT.SlideShowClicks.txt PPT.Table.ApplyStyle.txt PPT.TableBackground.txt PPT.TableProperties.txt PPT.WorkWithMediaPlayer.txt PPT.WorkWithSections.txt PPT.WorkWithSmartArt.txt
资源推荐
资源详情
资源评论
















格式:pdf 资源大小:190.1MB 页数:127















收起资源包目录


























共 24 条
- 1

zhanlingyun
- 粉丝: 3
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助


最新资源
- devtools_resources
- deepseek和langchain一起用于实现RAG
- devtools_resources
- devtools_resources
- EnCase_Forensic_Imager_7.06.zip
- EnCase_7.06
- EnCase_7.06
- global.prop.zip
- global.prop.zip
- 一个简单的矢量控制Matlab/Simulink仿真
- 一个简单的矢量控制Matlab/Simulink仿真
- SmartNest标准版
- SmartNest标准版
- SmartNest标准版
- visionpro案例.zip
- 2023年电子商务求职信150字左右-电子商务求职信800字中职(8篇).docx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈



安全验证
文档复制为VIP权益,开通VIP直接复制

- 1
- 2
前往页