[英]Executable not running correctly after being called from a VBA Excel Macro
I have an executable "Operate.exe" which reads data from a text file "Weightings.txt" and performs some operations on it. 我有一个可执行文件“ Operate.exe”,该文件从文本文件“ Weightings.txt”中读取数据并对其执行一些操作。 This runs fine when executed independently. 单独执行时,运行良好。
I'm trying to execute this from a button in excel using VBA. 我正在尝试使用VBA从excel中的按钮执行此操作。 The program runs, but "weightings.txt" is not being open/found. 该程序运行,但未打开/找到“ weightings.txt”。
This is the code I'm using in VBA: 这是我在VBA中使用的代码:
Sub TextBox1_Click()
Shell ThisWorkbook.Path & "\Operate.exe", vbNormalFocus
End Sub
The folder contains Operate.exe, Operate.pdb, Game.xlsm and Weightings.txt. 该文件夹包含Operate.exe,Operate.pdb,Game.xlsm和Weightings.txt。
Is Weightings.txt not being found because the exe program is being run from VBA? 是否由于从VBA运行exe程序而找不到Weightings.txt?
Change the current default working directory to the ThisWorkbook.Path. 将当前的默认工作目录更改为ThisWorkbook.Path。
Sub TextBox1_Click()
Debug.Print CurDir
ChDir ThisWorkbook.Path
Debug.Print CurDir
Shell ThisWorkbook.Path & "\Operate.exe", vbNormalFocus
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.