excel vba 通过参数将数据作为参数发送到 vbscript

这可能看起来很啰嗦,但希望有人能明白我的意思。

我的团队使用 Macro Express Pro 构建宏。几年前,我们使用 VBScript 开发了宏跟踪,以查看是否正在使用宏、由谁和多少人使用,并查看收集的某些数据以查看他们是否正确支付索赔。这将由单独的宏调用。唯一的工作就是接受调用宏作为参数发送给它的内容,然后调用 VBScript 并将参数作为 VBScript 将接收和处理的参数发送。从那时起,VBScript 不断发展,并真正向我们展示了我们正在寻找的数据。

最近,我们中的一些人一直在使用 VBA 在 Excel 中构建最终用户工具。我们的领导层要求这些工具也使用相同的 VBScript 进行跟踪。由于调用 Macro Express Pro 宏将数据发送到 VBScript 是没有意义的,因此我们尝试将直接从 VBA 代码收集的数据发送到 VBScript。

以下是将数据发送到 VBScript 时 Macro Express Pro 跟踪宏的作用:

在此处输入图片说明

以下是 VBScript 捕获该信息的方式:

' Sets up the object variables.
Option Explicit
Dim objFSO, objTextFile, conn

' Sets up the all the string variables for the program.
Dim Arg, UserID, MyDocs, strTextFile, strTextLine, strDataLine, Macro_Name, User_ID
Dim Run_Time, Claim_Number, strSQLData(28), dbHeader, dbSQLData, strConnect, message
Dim value1, value2, value3, value4, value5, value6, value7, value8, value9, value10, value11
Dim value12, value13, value14, value15, value16, value17, value18, value19, value20
Dim StartTime, EndTime, Macro_FileName, Ver, strSQL, strTrackVar
Dim strcount, i

'This creates the required Objects
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set Arg = Wscript.Arguments

strcount = Wscript.Arguments.Count

For i = 0 to strcount - 1
    If strTextLine = "" Then
        strTextLine = Arg.item(i)
    Else
        strTextLine = strTextLine & "," & Arg.item(i)
    End If
Next

'------------------Calls up the Process Tracking Submission sub-------------------

ProcessTrackingSubmission

Sub ProcessTrackingSubmission()

' Set up the origin and destination files

on error resume next
    ' Read the entire origin file and store as an array usable variables
    strDataLine = Split(strTextLine, ",")

    Macro_FileName = strDataLine(0)
    Macro_FileName= objFSO.GetFile(Macro_FileName).Name

    Macro_Name = strDataLine(1)
    User_ID = strDataLine(2)
    StartTime = strDataLine(3)
    EndTime = strDataLine(4)
    Claim_Number = strDataLine(5)

    If strDataLine(5) <> "" Then
        value1 = strDataLine(6)
    End If
    If strDataLine(6) <> "" Then
        value2 = strDataLine(7)
    End If
    If strDataLine(7) <> "" Then
        value3 = strDataLine(8)
    End If
    If strDataLine(8) <> "" Then
        value4 = strDataLine(9)
    End If
    If strDataLine(9) <> "" Then
        value5 = strDataLine(10)
    End If
    If strDataLine(10) <> "" Then
        value6 = strDataLine(11)
    End If
    If strDataLine(11) <> "" Then
        value7 = strDataLine(12)
    End If
    If strDataLine(12) <> "" Then
        value8 = strDataLine(13)
    End If
    If strDataLine(13) <> "" Then
        value9 = strDataLine(14)
    End If
    If strDataLine(14) <> "" Then
        value10 = strDataLine(15)
    End If
    If strDataLine(15) <> "" Then
        value11 = strDataLine(16)
    End If
    If strDataLine(16) <> "" Then
        value12 = strDataLine(17)
    End If
    If strDataLine(17) <> "" Then
        value13 = strDataLine(18)
    End If
    If strDataLine(18) <> "" Then
        value14 = strDataLine(19)
    End If
    If strDataLine(19) <> "" Then
        value15 = strDataLine(20)
    End If
    If strDataLine(20) <> "" Then
        value16 = strDataLine(21)
    End If
    If strDataLine(21) <> "" Then
        value17 = strDataLine(22)
    End If
    If strDataLine(22) <> "" Then
        value18 = strDataLine(23)
    End If
    If strDataLine(23) <> "" Then
        value19 = strDataLine(24)
    End If
    If strDataLine(24) <> "" Then
        value20 = strDataLine(25)
    End If

    InsertIntoDatabase()

End Sub

已编辑

我们正在寻找的是一种执行类似于以下操作的方法,该方法调用外部程序并将数据存储在 Windows 剪贴板上:

' This is used for tracking purposes
StartTime = Now
Set wshShell = CreateObject("Wscript.Shell")
MacroFile = "Stand-alone Tool"
CurrentMacro = "VBA Tracking Test.xlsm"
UserId = Environ("UserName")
ScriptPath = Environ("UserProfile") & "\Documents\Insight Software\Macro Express\Macro Logs\"
ScriptFile = ScriptPath & "SMT_SP_v3.vbs"
ClaimNum = "1234567890"
EndTime = Now

wshShell.Run """" & ScriptFile & """" & MacroFile & """ """ & CurrentMacro & """ """ & UserId & """ """ & StartTime & """ """ & _
EndTime & """ """ & ClaimNum & """ """ & Value1 & """ """ & Value2 & """ """ & Value3 & """ """ & Value4 & """ """ & Value5 & """ """ & _
Value6 & """ """ & Value7 & """ """ & Value8 & """ """ & Value9 & """ """ & Value10 & """ """ & Value11 & """ """ & Value12 & """ """ & _
Value13 & """ """ & Value14 & """ """ & Value15 & """ """ & Value16 & """ """ & Value17 & """ """ & Value18 & """ """ & Value19 & """ """ & Value20

然后使用以下方法收集该数据:

Set Arg = Wscript.Arguments

strcount = Wscript.Arguments.Count

For i = 0 to strcount - 1
    If strTextLine = "" Then
        strTextLine = Arg.item(i)
    Else
        strTextLine = strTextLine & "," & Arg.item(i)
    End If
Next

希望这不会太令人困惑。有人对如何做到这一点有任何建议吗?我没有在网上找到任何相关的东西,我已经在 SO 上搜索了可能的重复项。我们正在尝试的解决方案是将参数从 vba 传递到 vbs的变体,但它不起作用。

感谢omegastripes,我现在能够完成任务。虽然这“可能看起来像其他例子”,但我一直在寻找特定的东西,并且 omegastripes 出现了。这是代码:

' This is used for tracking purposes
StartTime = Now
Set wshShell = CreateObject("Wscript.Shell")
MacroFile = "Stand-alone Tool"
CurrentMacro = "VBA Tracking Test.xlsm"
UserId = Environ("UserName")
ScriptPath = Environ("UserProfile") & "\Documents\Insight Software\Macro Express\Macro Logs\"
ScriptFile = ScriptPath & "SMT_SP_v3.vbs"
ClaimNum = "1234567890"
EndTime = Now

wshShell.Run """" & ScriptFile & """ """ & MacroFile & """ """ & CurrentMacro & """ """ & UserId & """ """ & StartTime & """ """ & _
EndTime & """ """ & ClaimNum & """ """ & Value1 & """ """ & Value2 & """ """ & Value3 & """ """ & Value4 & """ """ & Value5 & """ """ & _
Value6 & """ """ & Value7 & """ """ & Value8 & """ """ & Value9 & """ """ & Value10 & """ """ & Value11 & """ """ & Value12 & """ """ & _
Value13 & """ """ & Value14 & """ """ & Value15 & """ """ & Value16 & """ """ & Value17 & """ """ & Value18 & """ """ & Value19 & """ """ & Value20 & """"

我能够通过查看数据库来确认所有数据都得到了完美的跟踪。再次感谢。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

为什么此VBScript在Excel VBA中可以正常运行,但又可以作为独立的vbscript运行?

将VBA转换为VBScript

尝试发送到Excel加载项时Excel VBA SendKeys不起作用

使用VBScript将Excel视图更改为页面布局

Excel VBA-通过列表作为函数参数

Excel VBA将参数传递给OLEDBConnection

从VBA Excel宏功能获取VBscript中的价值

数据标签VBA Excel

从Excel VBA发送短信

Selenium VBA(excel)将一系列单元格值发送到网页文本输入字段

通过Jenkins触发VBScript时,Excel不可见

Excel VBA将文本消息发送到Whatsapp

通过VBA发送到Google搜索时,带有特殊字母的Excel单元格值无法识别

通过VBA将数据发送到另一个工作簿

VBScript for Excel:如何选择源数据(.SetSourceData)?

Excel VBA常数作为参数

Vbscript。您如何将密钥发送到SWbemObject?

如何从vbscript执行vba

如何在Excel VBA函数中将日期作为参数传递

创建VBScript文件Excel

我正在尝试将CVS转换为VBSCRIPT中的EXCEL

Excel:从工作表中调用vba函数时,将当前单元格作为参数传递

通过发布将数据发送到url以使用javascript导出到excel

VBScript:在 VBA (Excel) 中使用 Shape 属性

有没有办法在 VBScript 中运行 Excel VBA 模块

将输入文件从 Excel VBA 发送到 Raspberry Pi 而不更改内容

使用 Outlook VBA 将邮件类别数据发送到 Excel

将参数从 VbScript 传递给 vba 函数

将 SQL 查询发送到 Excel VBA 上的 CSV 文件不适用于日期列