Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
229 views
in Technique[技术] by (71.8m points)

How to run CreateObject() in VBA code with .exe generated in CodeBlocks IDE

I am trying to generate an .exe file an integrate it with my Excel VBA code.

I am using CodeBlocks IDE to generate the .exe, Excel2013 and CodeBlocks2013 versions on a 64-bit computer.

I created my CodeBlocks project (my_program1) in two ways i.e. "Console Application" and "Empty Project", and compiled the project successfully in both the cases.

When I run the .exe from command prompt, I am able to get desired results in both cases.

However, when I run the same commands by invoking the .exe from my VBA code, it shows no results i.e. blank.

I printed out the commands which my VBA code executes and found that they as same as the commands which i use in the command prompt (correct file paths etc.)

When I execute the command via command prompt i.e. D:my_program1.exe list, i get the names in my command prompt.

Following is part of my VBA code:

//list = command which my_program accepts and returns list of names
command_for_name = ActiveWorkbook.Path & "my_program1.exe list"
//here, message box shows D:my_program1.exe list
MsgBox command_for_name  
//names returned by my_program1 to be seen in cell F7
Cells(7, "f").Value = CreateObject("WScript.Shell").Exec("cmd.exe /S /C" & command_for_name).StdOut.ReadAll

However, Cell F7 is blank.

I even tried.

MsgBox CreateObject("WScript.Shell").Exec("cmd.exe /S /C" & command_for_name).StdOut.ReadAll

however, the message box is also blank.

What should I change to get the .exe to work with my VBA code?

Thanks a lot in advance!

question from:https://stackoverflow.com/questions/65874313/how-to-run-createobject-in-vba-code-with-exe-generated-in-codeblocks-ide

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...