保存后在“我的文档"中创建Excel加载项的副本 [英] A copy of Excel Addin is created in My Documents after saving

查看:125
本文介绍了保存后在“我的文档"中创建Excel加载项的副本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个通过OLE自动化创建新Excel对象的应用程序(在IBM Notes中运行,使用Lotusscript等).在我的应用程序中,我创建一个新的工作簿并将其保存到一个临时文件夹(我将其保存为Excel Worksheet w/o macros-> type 52),以便重新创建文件.像这样:

I have an application (running in IBM Notes, using Lotusscript etc.) that create a new Excel object via OLE automation. In my app I create a new Workbook and saving it to a temporary folder (I am saving it as Excel Worksheet w/o macros -> type 52) so that the resuting file is sth. like that:

tmp_abc1234.xlsx

然后,我以编程方式在Excel中打开文件.我有一个Excel加载项(文件名是"Teamoffice.xlam",加载了一些宏所在的位置,我将在自定义保存操作栏按钮中触发.在此保存方法中,我还调用了保存功能:

Then I open the file in Excel programmatically. I have an Excel Addin (filename is "Teamoffice.xlam" loaded where some macros reside I will trigger in the custom save actionbar button. In this save method I also call the save function:

Call ActiveWorkbook.Save
Call ThisWorkbook.Save

由于某种原因,Excel在我的文档"文件夹中创建了一个名为"Teamoffice.xlsm"的文件.该文件本身无法在Excel中打开(错误的文件格式错误")-当然,这是一个插件!

For some reason Excel creates a file named "Teamoffice.xlsm" in the "My Documents" folder. The file itself cannot be opened in Excel ("wrong file format error") - of course, it's an Addin!

如果我从应用程序中仅打开一个Excel文档,则此方法效果很好.如果我打开第二个(或多个)文件,则会遇到麻烦:每次我保存那些次要打开的(或新创建的)文档时,Excel都会询问我是否要覆盖该"Teamoffice.xlsm"文件.

This works well if I have only one Excel document open from my application. If I open a second (or more) I run into trouble: everytime I save on of those secondary opened (or newly created) documents Excel asks me if I want to overwrite that "Teamoffice.xlsm" file.

我向ma宏添加了VBA代码,该宏可检测该文件是否存在并尝试将其删除.当然运气不好,因为Excel的第一个实例已经锁定了该文件.虽然在询问Excel问题对话框时覆盖文件是可行的,但是我不希望出现该问题.

I added VBA code to ma macro that detects if this file is there and tries to delete it. With no luck of course, as the first instance of Excel is locking that file already. Overwriting the file when aswering the Excel-question dialog works though, but I don't want that question to appear.

在不带OLE的情况下使用Excel时,Excel的行为不像这样.

Excel doesn't behave like that when using it stand-alone w/o OLE.

此行为引起的几个问题:

Several questions resulting from this behavior:

  1. 为什么Excel会创建此文件?我可以阻止它这样做吗?
  2. 即使Excel带有句柄,如何删除文件,也可以
  3. 我可以告诉Excel在该文件上没有句柄(如果存在)并让我杀死它吗?
  4. 我可以隐藏问题对话框并总是说是,覆盖它"吗?

Office版本是2010年-它使我发疯...所以预先感谢! 附言:我不是那个VBA专业人士,所以请尽可能详细:-)

Office version is 2010 - and it makes me going nuts... so thanks in advance! p.s.: I am not that VBA pro, so please be as detailed as you can effort :-)

推荐答案

我注意到了

ThisWorkbook.Save

是原因.如果我忽略它,则不会创建任何文件.奇怪的是,这虽然将Addin文件另存为xlsm文件.

was the reason. If I omit it no file is created. Strange that this saved the Addin file as xlsm file though.

这篇关于保存后在“我的文档"中创建Excel加载项的副本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆