在不同的Excel文件中使用一个宏 [英] use one macro in different excel files

查看:893
本文介绍了在不同的Excel文件中使用一个宏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个宏,我想在不同的excel文件中使用,这些文件具有几乎相同的表格结构但不同的数据。



所以这是可能的只是为了包含我的宏脚本到任何excel文件?



我已经读了这个提示,但对我来说听起来像个坏笑话。



谢谢

解决方案

您需要将文档另存为Excel加载项(.xla)并进行分发。然后,用户可以去工具>加载项安装加载项,他们需要浏览到您发送的文件,并验证加载项是否在添加在列表中。请注意,加载项不会显示在 Alt + F8 工具>宏中。您需要在加载项代码中为其创建菜单。请看这篇文章 http://spreadsheetpage.com/index.php/tip/creating_custom_menus/


如果您希望您的代码在所有工作簿中可用,请使用您的
PERSONAL .XLS Excel 2007-2010 中的 PERSONAL.XLSB 文件。这些通常位于您的文档和设置下的 XLSTART 文件夹中。


这是一个隐藏的工作簿,当您启动Excel时打开。
您在此工作簿中复制的代码可在您在Excel中打开的所有工作簿中使用。



最简单的方法是记录一个虚拟宏,然后在存储宏下拉列表中选择个人宏工作簿。



打开宏编辑器( ALT + F9 ),然后保存 PERSONAL.XLS 文件。写一个宏,例如

 公共子测试()
MsgBoxHey im from Personal.xls
End Sub




请记住隐藏名为 personal.xls 窗口>>隐藏)。现在在任何工作簿上,这个宏是可用的。



I wrote a macro, which I would like to use in different excel files, which have almost the same table structure but different data.

So is it possible anyhow just to "include" my macro-script to any excel file?!

I read already this tip but it sounds for me like a bad joke.

Thank you

解决方案

You need to save the document as an Excel Add-in (.xla) and distribute that. Users can then go Tools>Add-ins to install the add in. They will need to browse to the file you sent them and verify the add-in is checked on the add-in list. Note that add-ins do not show up in Alt+F8 or in Tools>Macro. You need to make a menu for that in your add-in code. see this post http://spreadsheetpage.com/index.php/tip/creating_custom_menus/

If you want your code to be available in all your workbooks, then use your PERSONAL.XLS or in Excel 2007-2010 your PERSONAL.XLSB file. These are normally held in the XLSTART folder under your documents and settings.

This is a hidden workbook that opens when you start Excel. The code you copy in this workbook is available in all workbooks you have opened in Excel.

The easiest way to make one is to record a dummy macro, then select Personal Macro Workbook under the Store The Macro in drop-down list.

Open up macro editor (ALT+F9) and then save the PERSONAL.XLS file. write up a macro, e.g

Public Sub Testing()
    MsgBox "Hey im from Personal.xls"
End Sub

Remember to hide the workbook named personal.xls (Window>>Hide). Now on any workbook, this macro is available.

这篇关于在不同的Excel文件中使用一个宏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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