做PowerPoint的VSTO插件项目,遇到个很奇怪的问题,当代码执行删除某些Shape时,没问题,但是操作Undo也就是恢复后,无法再次获取到之前删除的对象,这种情况只在Office2007中出现,亲测2010没问题。

就在快要放弃的时候,终于看到了这个

传送门:https://www.add-in-express.com/creating-addins-blog/2014/06/24/exception-hresult-0x800a01a8/

关键内容搬运如下:

private void adxRibbonButton1_OnClick(object sender, IRibbonControl control, bool pressed) {
PowerPoint.DocumentWindow activeWindow = PowerPointApp.ActiveWindow;
if (activeWindow != null) {
PowerPoint.View view = activeWindow.View;
if (view != null) {
object obj = view.Slide;
if (obj != null) {
if (obj is PowerPoint.Slide) {
PowerPoint.Shapes shapes = (obj as PowerPoint.Slide).Shapes;
if (shapes.HasTitle == Microsoft.Office.Core.MsoTriState.msoTrue) {
PowerPoint.Shape titleShape = shapes.Title;
object titleParent = null;
try {
titleParent = titleShape.Parent;
} catch (Exception ex) {
MessageBox.Show(ex.Message);
}
if (titleParent != null) {
// use titleParent
}
titleShape.Delete();
// leaving the COM object below unreleased causes 0x800A01A8 if you click Undo in the PP UI and invoke this code anew
Marshal.ReleaseComObject(titleShape); titleShape = null;
}
Marshal.ReleaseComObject(shapes); shapes = null;
}
Marshal.ReleaseComObject(obj); obj = null;
}
Marshal.ReleaseComObject(view); view = null;
}
Marshal.ReleaseComObject(activeWindow); activeWindow = null;
}
}

理解后,很容易就解决了这个问题,分享一下

VSTO PowerPoint 代码删除Shape后再恢复出现无法再次获取的问题的更多相关文章

  1. windows 10 删除库后自动恢复的解决方法

    目录 什么是windows 库? 手动删除不行吗? 如何正确的"删除"? title: windows 10 删除库后自动恢复的解决方法 date: 2019-06-09 15:4 ...

  2. django 删除表后如何恢复

    大家都知道Python manage.py makemigrations 创建迁移文件也就是sql语句,python manage.py migrate执行makemigrations创建的文件,如果 ...

  3. kafka删除topic后再创建同名的topic报错(ERROR org.apache.kafka.common.errors.TopicExistsException)

    [hadoop@datanode3 logs]$ kafka-topics.sh --delete --zookeeper datanode1:2181 --topic firstTopic firs ...

  4. k8s删除节点后再重新添加进去(踩坑)

    开启本地集群,发现一台节点出问题了,想删除再换一台节点,结果就踩坑了,还好本地有好几套环境. 再master节点执行以下命令 [root@k8s-master ~]# kubectl drain k8 ...

  5. ios8中,相册创建后手动删除,不能再进行创建显示

    // Add a new ALAssetsGroup to the library. // The name of the ALAssetsGroup is name and the type is ...

  6. [转载] mysql5.6 删除之前的ibdata1文件后再重新生成,遇到[Warning] Info table is not ready to be used. Table 'mysql.slave_master_info' cannot be opened.问题

    [转载] mysql5.6 删除之前的ibdata1文件后再重新生成,遇到[Warning] Info table is not ready to be used. Table 'mysql.slav ...

  7. id 自增------删除数据后恢复到删除前自增id

    删除数据后,执行下面语句: ALTER TBALE TableName AUTO_INCREMENT=1 mysql删除比较 一.DROP drop  table tablename 绝招:删除内容和 ...

  8. 无备份mysql删除表后恢复

    mysql从5.6.17开始自动设置innodb_file_per_table为on,每个表设置单独表空间,数据不是集中存放在ibdata1里.下面测试下无备份后drop表后的恢复. 前奏生成数据字典 ...

  9. 在用easyui中做CRUD功能时,当删除一行或多行数据后再点击修改会提示你选中了多行,如何解决这个bug了?

    在用easyui中做CRUD功能时,当删除一行或多行数据后再点击修改会提示你选中了多行,如何解决这个bug了? 在删除成功后,加上这句话就可以了:$("#dg").datagrid ...

随机推荐

  1. Lis日常维护

    1.[问题]护士站打印LIs条码,出来是PDF格式的 [解决]在文件夹Client\NeusoftLis\Xml\Print.xml中把BarcodePrint Name的值改成安装的斑马打印机名(不 ...

  2. 新手学跨域之iframe

    https://segmentfault.com/a/1190000000702539 页面嵌套iframe是比较常见的,比如QQ相关业务页面的登录框一般都是iframe的.使用ifrmae跨域要满足 ...

  3. [LeetCode] Flip Game 翻转游戏之二

    You are playing the following Flip Game with your friend: Given a string that contains only these tw ...

  4. [LeetCode] 3Sum Closest 最近三数之和

    Given an array S of n integers, find three integers in S such that the sum is closest to a given num ...

  5. CentOS安装Redis

    wget http://download.redis.io/redis-stable.tar.gz tar xvzf redis-stable.tar.gz cd redis-stable make ...

  6. 给空签名包进行签名以及找不到keystore证书链问题的解决方案

    转 http://blog.csdn.net/u011106842/article/details/49683865

  7. PRINCE2特征(二)

    英国体系环境下项目有什么特征(二) 今天又要和大家分享了,这个时间也是自己很喜欢的时刻.上次给大家分享的是英国体系下项目的特征之一:临时性.不知道大家还有没有印象,英国体系下项目的特征有五个,今天来给 ...

  8. 获取文件的缩略图Thumbnail和通过 AQS - Advanced Query Syntax 搜索本地文件

    演示如何获取文件的缩略图 FileSystem/ThumbnailAccess.xaml <Page x:Class="XamlDemo.FileSystem.ThumbnailAcc ...

  9. 使用Amoeba for mysql实现mysql读写分离

    Amoeba主要在应用层访问MySQL的时候充当query 路由功能,专注 分布式数据库 proxy 开发.座落与Client.DB Server(s)之间.对客户端透明.具有负载均衡.高可用性.Qu ...

  10. 封装js的部分兼容性

    //获取标签的内容(兼容所有浏览器)function getInnerText(element) { //能力检测(先判断如果这个能力有这个) if(typeof element.innerText ...