使用 VBA 运行 Node.js [英] Run Node.js using VBA

查看:68
本文介绍了使用 VBA 运行 Node.js的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

总体目标是在 JavaScript 文件上运行 Node.js 并使用 MS Access VBA 抓取输出.这是我用来测试的 JavaScript 文件:

The overall goal is to run Node.js on a JavaScript file and scrape the output using MS Access VBA. Here's the JavaScript file I'm using to test:

// C:\Users\micha\OneDrive\AppAcademy\Interview Prep\tst.js

var fs = require("fs");
var outputFile = "testLog.txt";

fs.writeFile(outputFile, new Date());

当我按如下方式从命令提示符运行它时,它会在面试准备文件夹中生成一个带有时间戳的 testLog.txt 文件.

When I run this from the command prompt as follows, it generates a testLog.txt file with a timestamp in the Interview Prep folder.

C:\Users\micha\OneDrive\AppAcademy\Interview Prep>node tst.js

现在我想在 Access 应用程序中使用 VBA 触发同样的事情.我试过两种方法.第一个是快速而肮脏的,但我的理解是我可以用 StdOut 来充实它作为抓取位.它使用 WScript.Shell:

Now I want to trigger the same thing using VBA from within an Access app. I've tried it two ways. The first is quick and dirty, but my understanding is that I can flesh it out with StdOut for the scraping bit. It uses WScript.Shell:

Private Sub runShellTest_Click()
    Dim objShell As Object, objExec As Object
    Set objShell = CreateObject("WScript.Shell")
    Set objExec = objShell.Exec("C:\Program Files\nodejs\node.exe C:\Users\micha\OneDrive\AppAcademy\Interview Prep\tst.js")
End Sub

当我运行它时,一个命令提示符会在屏幕上短暂闪烁,但我没有得到一个新的 testLog.txt.

When I run it, a command prompt briefly flashes onscreen, but I don't get a new testLog.txt.

我尝试的另一种方法更快更脏:

The other way I tried is even quicker and dirtier:

Private Sub runShellTest_Click()
    MsgBox (Shell("C:\Program Files\nodejs\node.exe C:\Users\micha\OneDrive\AppAcademy\Interview Prep\tst.js", vbNormalFocus))
End Sub

再次,命令提示符短暂闪烁,并且没有新的 testLog.txt.但是,消息框按预期显示了任务 ID,所以我猜……发生了什么事?

Again, the command prompt flashes up briefly, and there's no new testLog.txt. However, the message box shows a task ID as expected, so I guess... something happened?

感谢任何帮助!

推荐答案

我一直在尝试成功发送 xmlhttp 请求.您需要将 json 转换为 vba 字典.您可以使用一个 vba 类进行转换.

I'm been playing with that successfully sending xmlhttp request. You will need converting json to vba dictionary. There is a vba class you can use for the conversion.

这篇关于使用 VBA 运行 Node.js的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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