您好我创建的宏为我的合作工人。目前的方法,我对分配给另一台计算机进入VBA编辑器和进口。
Hello I create many macros for my co workers. The current method I have for distributing to another computer is going into the vba editor and importing.
我真的想做出一种安装程序的宏,允许用户安装一个新的宏,而不必进入编辑器。我不知道这甚至有可能,但任何想法,欢迎!
I would really like to make a kind of "installer" for macros that would allow the user to install a new macro without having to go into the editor. I'm not sure this is even possible but any ideas are welcome!
谢谢!
您需要启用在参考Microsoft脚本运行时库。 (VBE - >工具 - >引用勾选)
You need to enable Microsoft Scripting Runtime library under references. (VBE -> Tools -> References. Check the box.)
基本上,你创建包含要安装宏的code字符串。很显然,该字符串可能是很长的与code多行,所以你可能需要多个字符串变量。
Basically, you create a string that holds the code of the macro you want to install. Obviously, the string could be really long with many lines of code so you might need several string variables.
Dim toF As Workbook
Dim codeMod As CodeModule
Dim code As String
Dim fso As Scripting.FileSystemObject
Dim folder As folder
Dim name As String, file As String
Application.ScreenUpdating = False
Set fso = New FileSystemObject
Set folder = fso.GetFolder("C:\folder\here")
name = nameOfFileHere
file = folder & "\" & name
Set toF = Workbooks.Open(file)
'modify ThisWorkbook to place it elsewhere
Set codeMod = toF.VBProject.VBComponents("ThisWorkbook").CodeModule
'erase everything if code already exists
If codeMod.CountOfLines > 0 Then
codeMod.DeleteLines 1, codeMod.CountOfLines
End If
'dump in new code
code = _
"Private Sub Workbook_Open()" & vbNewLine & _
" Dim user as String" & vbNewLine & _
" Dim target as String" & vbNewLine & _
" user = Application.UserName" & vbNewLine & _
" target = """ & findUser & """" & vbNewLine & _
" If user = target then" & vbNewLine & _
" MsgBox ""I just dumped in some code.""" & vbNewLine & _
" End if" & vbNewLine & _
"End Sub" & vbNewLine
With codeMod
.InsertLines .CountOfLines + 1, code
End With
Application.ScreenUpdating = True
上一篇:如何使AS3的Flash视频播放器?视频播放器、Flash
下一篇:我如何使用的ArrayCollection像在ActionScript 3.0的Flash IDE的功能?如何使用、功能、ArrayCollection、ActionScript