有时我们需要在PPT实现一些简单的交互:比如鼠标悬停在某个对象上,该对象进行放大,鼠标移开后对象恢复原尺寸。这种交互一般使用VBA实现。接下来,我用一个简单的缩放交互示例进行演示
1.1 新建或打开PowerPoint演示文稿
1.2 调出开发工具选项卡
PPT → 文件 → 选项 → 自定义功能区 →
勾选开发工具 → 确定
1.3 另存为pptm
按Ctrl+Shift+S快捷键 → 保存类型:
启用宏的PowerPoint演示文稿 → 确定
2.1 查看代码
开发工具选项卡 → 查看代码
2.2 插入模块
选中VBAProject右键 → 插入 → 模块
2.3 复制如下代码
Private oldshp As Shape
Sub ZoomShape(ByVal shp As Shape)
Dim mw As Single
Dim mh As Single
If oldshp Is Nothing Then
'mw = shp.Left + shp.Width / 2
mh = shp.Top + shp.Height / 2
shp.Width = shp.Width * 1.2
shp.Height = shp.Height * 1.2
shp.Left = mw - shp.Width / 2
shp.Top = mh - shp.Height / 2
Set oldshp = shp
End If
End Sub
Sub