How do I use VBA to open Console App and then enter data?











up vote
1
down vote

favorite












I have made a simple console app that takes data entered into it, transforms the data into the correct format, and submits it to an online database. The console app just needs the data entered into it, and it will do the rest.



For example, I would type something like this: "Description text [Enter]", "Customer name [Enter]", etc., etc.



I have several Excel workbooks that I would like to use this app. But I don't know how to use VBA to do the following:




  1. Run the Console App

  2. Enter text into the console app from VBA for Excel.


How do I do this? Do I need to add additional references for Excel? Is this possible? If this isn't possible, what would you recommend doing instead?



Thank you in advance! This community has really helped so far.










share|improve this question






















  • Can't help you with your problem directly, but generally it would be easier if your console app would accept the data as command line arguments, (argv if you're using C/C++). If you don't need a return value from the command, that should be very easy, i.e. see this question: stackoverflow.com/q/2290365/2192139
    – Geier
    Nov 10 at 21:49










  • I may look into how to do the argument function. Thank you, @Geier!
    – Parker.R
    Nov 11 at 1:59















up vote
1
down vote

favorite












I have made a simple console app that takes data entered into it, transforms the data into the correct format, and submits it to an online database. The console app just needs the data entered into it, and it will do the rest.



For example, I would type something like this: "Description text [Enter]", "Customer name [Enter]", etc., etc.



I have several Excel workbooks that I would like to use this app. But I don't know how to use VBA to do the following:




  1. Run the Console App

  2. Enter text into the console app from VBA for Excel.


How do I do this? Do I need to add additional references for Excel? Is this possible? If this isn't possible, what would you recommend doing instead?



Thank you in advance! This community has really helped so far.










share|improve this question






















  • Can't help you with your problem directly, but generally it would be easier if your console app would accept the data as command line arguments, (argv if you're using C/C++). If you don't need a return value from the command, that should be very easy, i.e. see this question: stackoverflow.com/q/2290365/2192139
    – Geier
    Nov 10 at 21:49










  • I may look into how to do the argument function. Thank you, @Geier!
    – Parker.R
    Nov 11 at 1:59













up vote
1
down vote

favorite









up vote
1
down vote

favorite











I have made a simple console app that takes data entered into it, transforms the data into the correct format, and submits it to an online database. The console app just needs the data entered into it, and it will do the rest.



For example, I would type something like this: "Description text [Enter]", "Customer name [Enter]", etc., etc.



I have several Excel workbooks that I would like to use this app. But I don't know how to use VBA to do the following:




  1. Run the Console App

  2. Enter text into the console app from VBA for Excel.


How do I do this? Do I need to add additional references for Excel? Is this possible? If this isn't possible, what would you recommend doing instead?



Thank you in advance! This community has really helped so far.










share|improve this question













I have made a simple console app that takes data entered into it, transforms the data into the correct format, and submits it to an online database. The console app just needs the data entered into it, and it will do the rest.



For example, I would type something like this: "Description text [Enter]", "Customer name [Enter]", etc., etc.



I have several Excel workbooks that I would like to use this app. But I don't know how to use VBA to do the following:




  1. Run the Console App

  2. Enter text into the console app from VBA for Excel.


How do I do this? Do I need to add additional references for Excel? Is this possible? If this isn't possible, what would you recommend doing instead?



Thank you in advance! This community has really helped so far.







excel vba excel-vba console console-application






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 10 at 20:53









Parker.R

64




64












  • Can't help you with your problem directly, but generally it would be easier if your console app would accept the data as command line arguments, (argv if you're using C/C++). If you don't need a return value from the command, that should be very easy, i.e. see this question: stackoverflow.com/q/2290365/2192139
    – Geier
    Nov 10 at 21:49










  • I may look into how to do the argument function. Thank you, @Geier!
    – Parker.R
    Nov 11 at 1:59


















  • Can't help you with your problem directly, but generally it would be easier if your console app would accept the data as command line arguments, (argv if you're using C/C++). If you don't need a return value from the command, that should be very easy, i.e. see this question: stackoverflow.com/q/2290365/2192139
    – Geier
    Nov 10 at 21:49










  • I may look into how to do the argument function. Thank you, @Geier!
    – Parker.R
    Nov 11 at 1:59
















Can't help you with your problem directly, but generally it would be easier if your console app would accept the data as command line arguments, (argv if you're using C/C++). If you don't need a return value from the command, that should be very easy, i.e. see this question: stackoverflow.com/q/2290365/2192139
– Geier
Nov 10 at 21:49




Can't help you with your problem directly, but generally it would be easier if your console app would accept the data as command line arguments, (argv if you're using C/C++). If you don't need a return value from the command, that should be very easy, i.e. see this question: stackoverflow.com/q/2290365/2192139
– Geier
Nov 10 at 21:49












I may look into how to do the argument function. Thank you, @Geier!
– Parker.R
Nov 11 at 1:59




I may look into how to do the argument function. Thank you, @Geier!
– Parker.R
Nov 11 at 1:59












1 Answer
1






active

oldest

votes

















up vote
1
down vote













Ideally, your console app would take arguments instead of reading lines. Then you could simply invoke your executable from VBA as explained here.



If you can't modify the console app, you can work around this by first creating a temporary text file using VBA (numerous examples throughout this site). This file would contain the inputs you'd normally provide from the keyboard. Then, you'd invoke your executable as described in the linked answer, but instead of providing parameters, you'd use the < character to feed the contents of the temporary text file to the program:



Public Sub StartExeWithInputFile()
Dim strProgramName As String
Dim strInputFile As String

strProgramName = "C:Program FilesTestfoobar.exe"
strInputFile = "C:DataTempInputLines.txt" '<== You have to produce this file.

Call Shell("""" & strProgramName & """ <""" & strInputFile & """", vbNormalFocus)
End Sub


EDIT
Here's an example for creating the temporary input file mentioned above:



Sub CreateTempInputLines()
Dim fso As Object
Dim oFile As Object

Set fso = CreateObject("Scripting.FileSystemObject")

'See https://docs.microsoft.com/en-us/office/vba/language/reference/user-interface-help/createtextfile-method.
Set oFile = fso.CreateTextFile("C:DataTempInputLines.txt", True)

oFile.WriteLine "Description text"
oFile.WriteLine "Customer name"

'Cleanup.
oFile.Close
Set oFile = Nothing
Set fso = Nothing
End Sub





share|improve this answer























  • Great answer. The app opens perfectly, and the text is written correctly. Everything works except the input into the console app; it is just blank. I can even copy the contents of the .txt file, and it works. Any idea what it might be?
    – Parker.R
    Nov 11 at 1:58










  • Maybe you started the console app before closing the text file in VBA? The data might not be written to the text file until you close it.
    – Geier
    Nov 11 at 7:22










  • Put a breakpoint on the Shell line and Debug.Print what's within the parentheses. Copy the result and paste it into a command window. What happens? Note: I've built a console app that just calls Console.ReadLine(), and it works.
    – Excelosaurus
    Nov 11 at 19:52










  • Edited my answer to align the text file's path across subs; might explain why it did not work. Of course, make sure you create, write to and close the text file before calling Shell.
    – Excelosaurus
    Nov 12 at 2:33











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53243311%2fhow-do-i-use-vba-to-open-console-app-and-then-enter-data%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
1
down vote













Ideally, your console app would take arguments instead of reading lines. Then you could simply invoke your executable from VBA as explained here.



If you can't modify the console app, you can work around this by first creating a temporary text file using VBA (numerous examples throughout this site). This file would contain the inputs you'd normally provide from the keyboard. Then, you'd invoke your executable as described in the linked answer, but instead of providing parameters, you'd use the < character to feed the contents of the temporary text file to the program:



Public Sub StartExeWithInputFile()
Dim strProgramName As String
Dim strInputFile As String

strProgramName = "C:Program FilesTestfoobar.exe"
strInputFile = "C:DataTempInputLines.txt" '<== You have to produce this file.

Call Shell("""" & strProgramName & """ <""" & strInputFile & """", vbNormalFocus)
End Sub


EDIT
Here's an example for creating the temporary input file mentioned above:



Sub CreateTempInputLines()
Dim fso As Object
Dim oFile As Object

Set fso = CreateObject("Scripting.FileSystemObject")

'See https://docs.microsoft.com/en-us/office/vba/language/reference/user-interface-help/createtextfile-method.
Set oFile = fso.CreateTextFile("C:DataTempInputLines.txt", True)

oFile.WriteLine "Description text"
oFile.WriteLine "Customer name"

'Cleanup.
oFile.Close
Set oFile = Nothing
Set fso = Nothing
End Sub





share|improve this answer























  • Great answer. The app opens perfectly, and the text is written correctly. Everything works except the input into the console app; it is just blank. I can even copy the contents of the .txt file, and it works. Any idea what it might be?
    – Parker.R
    Nov 11 at 1:58










  • Maybe you started the console app before closing the text file in VBA? The data might not be written to the text file until you close it.
    – Geier
    Nov 11 at 7:22










  • Put a breakpoint on the Shell line and Debug.Print what's within the parentheses. Copy the result and paste it into a command window. What happens? Note: I've built a console app that just calls Console.ReadLine(), and it works.
    – Excelosaurus
    Nov 11 at 19:52










  • Edited my answer to align the text file's path across subs; might explain why it did not work. Of course, make sure you create, write to and close the text file before calling Shell.
    – Excelosaurus
    Nov 12 at 2:33















up vote
1
down vote













Ideally, your console app would take arguments instead of reading lines. Then you could simply invoke your executable from VBA as explained here.



If you can't modify the console app, you can work around this by first creating a temporary text file using VBA (numerous examples throughout this site). This file would contain the inputs you'd normally provide from the keyboard. Then, you'd invoke your executable as described in the linked answer, but instead of providing parameters, you'd use the < character to feed the contents of the temporary text file to the program:



Public Sub StartExeWithInputFile()
Dim strProgramName As String
Dim strInputFile As String

strProgramName = "C:Program FilesTestfoobar.exe"
strInputFile = "C:DataTempInputLines.txt" '<== You have to produce this file.

Call Shell("""" & strProgramName & """ <""" & strInputFile & """", vbNormalFocus)
End Sub


EDIT
Here's an example for creating the temporary input file mentioned above:



Sub CreateTempInputLines()
Dim fso As Object
Dim oFile As Object

Set fso = CreateObject("Scripting.FileSystemObject")

'See https://docs.microsoft.com/en-us/office/vba/language/reference/user-interface-help/createtextfile-method.
Set oFile = fso.CreateTextFile("C:DataTempInputLines.txt", True)

oFile.WriteLine "Description text"
oFile.WriteLine "Customer name"

'Cleanup.
oFile.Close
Set oFile = Nothing
Set fso = Nothing
End Sub





share|improve this answer























  • Great answer. The app opens perfectly, and the text is written correctly. Everything works except the input into the console app; it is just blank. I can even copy the contents of the .txt file, and it works. Any idea what it might be?
    – Parker.R
    Nov 11 at 1:58










  • Maybe you started the console app before closing the text file in VBA? The data might not be written to the text file until you close it.
    – Geier
    Nov 11 at 7:22










  • Put a breakpoint on the Shell line and Debug.Print what's within the parentheses. Copy the result and paste it into a command window. What happens? Note: I've built a console app that just calls Console.ReadLine(), and it works.
    – Excelosaurus
    Nov 11 at 19:52










  • Edited my answer to align the text file's path across subs; might explain why it did not work. Of course, make sure you create, write to and close the text file before calling Shell.
    – Excelosaurus
    Nov 12 at 2:33













up vote
1
down vote










up vote
1
down vote









Ideally, your console app would take arguments instead of reading lines. Then you could simply invoke your executable from VBA as explained here.



If you can't modify the console app, you can work around this by first creating a temporary text file using VBA (numerous examples throughout this site). This file would contain the inputs you'd normally provide from the keyboard. Then, you'd invoke your executable as described in the linked answer, but instead of providing parameters, you'd use the < character to feed the contents of the temporary text file to the program:



Public Sub StartExeWithInputFile()
Dim strProgramName As String
Dim strInputFile As String

strProgramName = "C:Program FilesTestfoobar.exe"
strInputFile = "C:DataTempInputLines.txt" '<== You have to produce this file.

Call Shell("""" & strProgramName & """ <""" & strInputFile & """", vbNormalFocus)
End Sub


EDIT
Here's an example for creating the temporary input file mentioned above:



Sub CreateTempInputLines()
Dim fso As Object
Dim oFile As Object

Set fso = CreateObject("Scripting.FileSystemObject")

'See https://docs.microsoft.com/en-us/office/vba/language/reference/user-interface-help/createtextfile-method.
Set oFile = fso.CreateTextFile("C:DataTempInputLines.txt", True)

oFile.WriteLine "Description text"
oFile.WriteLine "Customer name"

'Cleanup.
oFile.Close
Set oFile = Nothing
Set fso = Nothing
End Sub





share|improve this answer














Ideally, your console app would take arguments instead of reading lines. Then you could simply invoke your executable from VBA as explained here.



If you can't modify the console app, you can work around this by first creating a temporary text file using VBA (numerous examples throughout this site). This file would contain the inputs you'd normally provide from the keyboard. Then, you'd invoke your executable as described in the linked answer, but instead of providing parameters, you'd use the < character to feed the contents of the temporary text file to the program:



Public Sub StartExeWithInputFile()
Dim strProgramName As String
Dim strInputFile As String

strProgramName = "C:Program FilesTestfoobar.exe"
strInputFile = "C:DataTempInputLines.txt" '<== You have to produce this file.

Call Shell("""" & strProgramName & """ <""" & strInputFile & """", vbNormalFocus)
End Sub


EDIT
Here's an example for creating the temporary input file mentioned above:



Sub CreateTempInputLines()
Dim fso As Object
Dim oFile As Object

Set fso = CreateObject("Scripting.FileSystemObject")

'See https://docs.microsoft.com/en-us/office/vba/language/reference/user-interface-help/createtextfile-method.
Set oFile = fso.CreateTextFile("C:DataTempInputLines.txt", True)

oFile.WriteLine "Description text"
oFile.WriteLine "Customer name"

'Cleanup.
oFile.Close
Set oFile = Nothing
Set fso = Nothing
End Sub






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 12 at 2:26

























answered Nov 10 at 21:54









Excelosaurus

1,8481713




1,8481713












  • Great answer. The app opens perfectly, and the text is written correctly. Everything works except the input into the console app; it is just blank. I can even copy the contents of the .txt file, and it works. Any idea what it might be?
    – Parker.R
    Nov 11 at 1:58










  • Maybe you started the console app before closing the text file in VBA? The data might not be written to the text file until you close it.
    – Geier
    Nov 11 at 7:22










  • Put a breakpoint on the Shell line and Debug.Print what's within the parentheses. Copy the result and paste it into a command window. What happens? Note: I've built a console app that just calls Console.ReadLine(), and it works.
    – Excelosaurus
    Nov 11 at 19:52










  • Edited my answer to align the text file's path across subs; might explain why it did not work. Of course, make sure you create, write to and close the text file before calling Shell.
    – Excelosaurus
    Nov 12 at 2:33


















  • Great answer. The app opens perfectly, and the text is written correctly. Everything works except the input into the console app; it is just blank. I can even copy the contents of the .txt file, and it works. Any idea what it might be?
    – Parker.R
    Nov 11 at 1:58










  • Maybe you started the console app before closing the text file in VBA? The data might not be written to the text file until you close it.
    – Geier
    Nov 11 at 7:22










  • Put a breakpoint on the Shell line and Debug.Print what's within the parentheses. Copy the result and paste it into a command window. What happens? Note: I've built a console app that just calls Console.ReadLine(), and it works.
    – Excelosaurus
    Nov 11 at 19:52










  • Edited my answer to align the text file's path across subs; might explain why it did not work. Of course, make sure you create, write to and close the text file before calling Shell.
    – Excelosaurus
    Nov 12 at 2:33
















Great answer. The app opens perfectly, and the text is written correctly. Everything works except the input into the console app; it is just blank. I can even copy the contents of the .txt file, and it works. Any idea what it might be?
– Parker.R
Nov 11 at 1:58




Great answer. The app opens perfectly, and the text is written correctly. Everything works except the input into the console app; it is just blank. I can even copy the contents of the .txt file, and it works. Any idea what it might be?
– Parker.R
Nov 11 at 1:58












Maybe you started the console app before closing the text file in VBA? The data might not be written to the text file until you close it.
– Geier
Nov 11 at 7:22




Maybe you started the console app before closing the text file in VBA? The data might not be written to the text file until you close it.
– Geier
Nov 11 at 7:22












Put a breakpoint on the Shell line and Debug.Print what's within the parentheses. Copy the result and paste it into a command window. What happens? Note: I've built a console app that just calls Console.ReadLine(), and it works.
– Excelosaurus
Nov 11 at 19:52




Put a breakpoint on the Shell line and Debug.Print what's within the parentheses. Copy the result and paste it into a command window. What happens? Note: I've built a console app that just calls Console.ReadLine(), and it works.
– Excelosaurus
Nov 11 at 19:52












Edited my answer to align the text file's path across subs; might explain why it did not work. Of course, make sure you create, write to and close the text file before calling Shell.
– Excelosaurus
Nov 12 at 2:33




Edited my answer to align the text file's path across subs; might explain why it did not work. Of course, make sure you create, write to and close the text file before calling Shell.
– Excelosaurus
Nov 12 at 2:33


















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53243311%2fhow-do-i-use-vba-to-open-console-app-and-then-enter-data%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Florida Star v. B. J. F.

Danny Elfman

Retrieve a Users Dashboard in Tumblr with R and TumblR. Oauth Issues