excel - 从 MS Excel VBA 宏启动 .bat 文件(通过 SQLcl 连接到 Oracle)
问题描述
我正在编写一个需要:
- 启动 .bat 文件
- 等到 .bat 文件完成(数据通过 SQLcl 从 Oracle 下载到 .csv)
- 继续执行 VBA 的其余部分
我为这个问题找到了两种解决方案:
第一个 - 通过壳牌:
Dim shell_command As String
shell_command = ".bat_file_location"
Call Shell(shell_command, vbNormalFocus)
这会打开 .bat 文件,但窗口会立即关闭并且不执行任何操作。
第二个 - 通过 Windows 脚本宿主对象:
Dim strCommand As String
Dim lngErrorCode As Long
Dim wsh As WshShell
Set wsh = New WshShell
strCommand = Chr(34) & _
".bat_file_location" & _
Chr(34)
lngErrorCode = wsh.Run(strCommand, _
WindowStyle:=0, _
waitonreturn:=True)
If lngErrorCode <> 0 Then
MsgBox "Uh oh! Something went wrong with .bat file!"
Exit Sub
End If
Set wsh = Nothing
此选项不起作用(lngErrorCode=0),我不太清楚为什么。我对其他通过 BTEQ 从 Teradata 数据库下载数据的 .bat 文件使用相同的方法,因此我假设 SQLcl/Oracle 数据库不想使用该方法。
你有什么想法可以克服这个问题吗?
.bat 文件代码:
sql user/password@//hostname:port/servicename @"path\code.sql"
任何建议将不胜感激。问候。
解决方案
推荐阅读
- java - MessageQueue 回调中的异常:handleReceiveCallback 洪水填充算法 Android
- javascript - 通过预处理更改元素 ID 和类
- html - 如何修复 TypeError:无法读取未定义的属性“修剪”
- python - 我需要在矩形中添加文本,我该怎么做?
- reactjs - SweetAlert2 没有出现
- python - 当代码在 def 中时,canvas.create_image 不起作用:
- mysql - 有没有办法获取查询结果的列名
- scala - 如何在 sbt 交叉编译平台中运行特定的 scala-test?
- c++ - Qt: How to catch QDateEdit click event?
- opencv - How to calculate radius in orb?