Vba 在Excel中生成不需要最终用户安装的工具
是否可以在Microsoft Excel中生成不需要最终用户安装的工具/加载项 例如,我们使用VBA构建基于excel的工具,但该语言非常基础。是否有其他类似于VBA或VSTO的技术 谢谢, 贾扬斯Vba 在Excel中生成不需要最终用户安装的工具,vba,vsto,Vba,Vsto,是否可以在Microsoft Excel中生成不需要最终用户安装的工具/加载项 例如,我们使用VBA构建基于excel的工具,但该语言非常基础。是否有其他类似于VBA或VSTO的技术 谢谢, 贾扬斯 不可以。(虽然管理员可以为用户执行此操作),但用户只需双击某些内容(excel工作表、word文档、批处理文件、vbsfile、jscript、exe(在开始-运行中键入iexpress) 它被称为Visual Basic,所以是的,它是基本的。但是该语言编写简单,功能不基本。它可以做任何其他语言可
iexpress
)Sub Randomise
Randomize
Set rs = CreateObject("ADODB.Recordset")
With rs
.Fields.Append "RandomNumber", 4
.Fields.Append "Txt", 201, 5000
.Open
Do Until Inp.AtEndOfStream
.AddNew
.Fields("RandomNumber").value = Rnd() * 10000
.Fields("Txt").value = Inp.readline
.UpDate
Loop
.Sort = "RandomNumber"
Do While not .EOF
Outp.writeline .Fields("Txt").Value
.MoveNext
Loop
End With
End Sub
或者说一行行文字的脚本
Sub Speak
Set objVoice = CreateObject("SAPI.SpVoice")
Do Until Inp.AtEndOfStream
Line=Inp.readline
outp.writeline Line
objVoice.Speak Line
Loop
End Sub
或者,您可能希望向项目中添加宏语言。这将对文件的每一行运行命令行上指定的vbs脚本。这包括语法检查等
Sub VBSCmd
RawScript = Arg(1)
'Remove ^ from quoting command line and replace : with vbcrlf so get line number if error
Script = Replace(RawScript, "^", "")
Script = Replace(Script, "'", chr(34))
Script = Replace(Script, ":", vbcrlf)
'Building the script with predefined statements and the user's code
Script = "Dim gU" & vbcrlf & "Dim gdU" & vbcrlf & "Set gdU = CreateObject(" & chr(34) & "Scripting.Dictionary" & chr(34) & ")" & vbcrlf & "Function UF(L, LC)" & vbcrlf & "Set greU = New RegExp" & vbcrlf & "On Error Resume Next" & vbcrlf & Script & vbcrlf & "End Function" & vbcrlf
'Testing the script for syntax errors
On Error Resume Next
set ScriptControl1 = wscript.createObject("MSScriptControl.ScriptControl",SC)
With ScriptControl1
.Language = "VBScript"
.UseSafeSubset = False
.AllowUI = True
.AddCode Script
End With
With ScriptControl1.Error
If .number <> 0 then
Outp.WriteBlankLines(1)
Outp.WriteLine "User function syntax error"
Outp.WriteLine "=========================="
Outp.WriteBlankLines(1)
Outp.Write NumberScript(Script)
Outp.WriteBlankLines(2)
Outp.WriteLine "Error " & .number & " " & .description
Outp.WriteLine "Line " & .line & " " & "Col " & .column
Exit Sub
End If
End With
ExecuteGlobal(Script)
'Remove the first line as the parameters are the first line
'Line=Inp.readline
Do Until Inp.AtEndOfStream
Line=Inp.readline
LineCount = Inp.Line
temp = UF(Line, LineCount)
If err.number <> 0 then
outp.writeline ""
outp.writeline ""
outp.writeline "User function runtime error"
outp.writeline "==========================="
Outp.WriteBlankLines(1)
Outp.Write NumberScript(Script)
Outp.WriteBlankLines(2)
Outp.WriteLine "Error " & err.number & " " & err.description
Outp.WriteLine "Source " & err.source
Outp.WriteLine "Line number and column not available for runtime errors"
wscript.quit
End If
outp.writeline temp
Loop
End Sub
子VBSCmd
RawScript=Arg(1)
'从引用命令行中删除“^”,并将:替换为vbcrlf,以便在出现错误时获取行号
脚本=替换(RawScript,“^”,“”)
脚本=替换(脚本“”,chr(34))
脚本=替换(脚本“:”,vbcrlf)
'使用预定义语句和用户代码构建脚本
Script=“Dim gU”&vbcrlf&“Dim gdU”&vbcrlf&“Set gdU=CreateObject”(&chr(34)&Scripting.Dictionary”&chr(34)&vbcrlf&“Function UF(L,LC)”&vbcrlf&“Set greU=New RegExp”&vbcrlf&“在错误恢复下一步”&vbcrlf&Script&vbcrlf&vbcrlf&“结束函数”&vbcrlf
'测试脚本的语法错误
出错时继续下一步
set ScriptControl1=wscript.createObject(“MSScriptControl.ScriptControl”,SC)
使用ScriptControl1
.Language=“VBScript”
.UseSafeSubset=False
.AllowUI=True
.AddCode脚本
以
使用ScriptControl1。错误
如果是0,那么
输出写入行(1)
Outp.WriteLine“用户函数语法错误”
Outp.WriteLine“===================================================================================================”
输出写入行(1)
Outp.Write NumberScript(脚本)
输出写入行(2)
Outp.WriteLine“错误”&.number&“&.description
Outp.WriteLine“行”和.Line&“列”和“列”和
出口接头
如果结束
以
ExecuteGlobal(脚本)
'删除第一行,因为参数是第一行
'行=Inp.readline
直到Inp.AtEndOfStream
Line=Inp.readline
行数=输入行
温度=UF(行数、行数)
如果错误号为0,则
输出写入线“”
输出写入线“”
outp.writeline“用户函数运行时错误”
outp.writeline“======================================================================================================”
输出写入行(1)
Outp.Write NumberScript(脚本)
输出写入行(2)
Outp.WriteLine“Error”和err.number&“err.description”
Outp.WriteLine“Source”和err.Source
Outp.WriteLine“行号和列不可用于运行时错误”
wscript.quit
如果结束
输出写入线温度
环
端接头
以及从对象到API调用的速度变化
这将创建一个在VB6之后发布的Richtext控件,因此它不是内置的
Ret = LoadLibrary("c:\windows\system32\MSFTEDIT.dll")
If Ret = 0 Then MsgBox "Load Lib " & Err.LastDllError
Flags = WS_CHILD + WS_HSCROLL + WS_VSCROLL + WS_VISIBLE + ES_MULTILINE + ES_AUTOHSCROLL + ES_AUTOVSCROLL + ES_NOHIDESEL + ES_WANTRETURN
Dim barray() As Byte
barray = "RICHEDIT50W" & vbNullChar
gRtfHwnd = CreateWindowEx(WS_EX_ACCEPTFILES + WS_EX_CLIENTEDGE, barray(0), "", Flags, 0, 0, ScaleX(Me.ScaleWidth, vbTwips, vbPixels), ScaleY(Me.ScaleHeight, vbTwips, vbPixels), Me.hWnd, vbNull, App.hInstance, vbNull)
Ret = SendMessageByVal(gRtfHwnd, EM_SETTEXTMODE, TM_MULTILEVELUNDO + TM_PLAINTEXT + TM_MULTICODEPAGE, 0)
If GetTextMode(gRtfHwnd) <> 41 Then MsgBox "get Text mode = " & GetTextMode(gRtfHwnd)
Ret = SendMessageByVal(gRtfHwnd, EM_SETEDITSTYLE, SES_ALLOWBEEPS + SES_USECRLF, SES_ALLOWBEEPS + SES_USECRLF)
Ret = SendMessageByVal(gRtfHwnd, EM_SETLANGOPTIONS, IMF_None, IMF_None)
If GetTextMode(gRtfHwnd) <> 41 Then MsgBox "get Text mode (2) = " & GetTextMode(gRtfHwnd)
Ret = SendMessageByVal(gRtfHwnd, EM_SETTYPOGRAPHYOPTIONS, TO_None, TO_None)
'Below is the default anyway with CreateWin flags spec above
Ret = SendMessageByVal(gRtfHwnd, EM_SETOPTIONS, ECO_AUTOHSCROLL + ECO_AUTOVSCROLL + ECO_NOHIDESEL + ECO_WANTRETURN, ECOOP_OR)
SetFocusAPI gRtfHwnd
Me.Show
Dim ParaFormat As ITextPara
Dim FontFormat As ITextFont
Ret = SendMessageAny(gRtfHwnd, EM_GETOLEINTERFACE, 0, TomObj)
Ret=LoadLibrary(“c:\windows\system32\MSFTEDIT.dll”)
如果Ret=0,则MsgBox“加载库”&Err.LastDllError
Flags=WS_CHILD+WS_HSCROLL+WS_VSCROLL+WS_VISIBLE+ES_MULTILINE+ES_AUTOHSCROLL+ES_AUTOVSCROLL+ES_NOHIDESEL+ES_WANTRETURN
Dim barray()作为字节
barray=“RICHEDIT50W”和vbNullChar
gRtfHwnd=CreateWindowEx(WS_EX_ACCEPTFILES+WS_EX_CLIENTEDGE,barray(0),“”,标志,0,0,ScaleX(Me.ScaleWidth,vbTwips,vbPixels),ScaleY(Me.ScaleHeight,vbTwips,vbPixels),Me.hWnd,vbNull,App.hInstance,vbNull)
Ret=SendMessageByVal(gRtfHwnd,EM_SETTEXTMODE,TM_多级撤消+TM_明文+TM_多部门,0)
如果GetTextMode(gRtfHwnd)41,则MsgBox“get Text mode=”&GetTextMode(gRtfHwnd)
Ret=SendMessageByVal(gRtfHwnd、EM_SETEDITSTYLE、SES_ALLOWBEEPS+SES_USECRLF、SES_ALLOWBEEPS+SES_USECRLF)
Ret=SendMessageByVal(gRtfHwnd、EM_SETLANGOPTIONS、IMF_None、IMF_None)
如果GetTextMode(gRtfHwnd)41,则MsgBox“获取文本模式(2)=”&GetTextMode(gRtfHwnd)
Ret=SendMessageByVal(gRtfHwnd、EM_设置输入法选项、至无、至无)
'下面是使用上面的CreateWin标志规范的默认设置
Ret=SendMessageByVal(gRtfHwnd、EM_设置选项、ECO_自动循环+ECO_自动循环+ECO_NOHIDESEL+ECO_WANTRETURN、ECOOP_或)
SetFocusAPI gRtfHwnd
我,嘘