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:
- Run the Console App
- 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
add a comment |
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:
- Run the Console App
- 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
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
add a comment |
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:
- Run the Console App
- 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
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:
- Run the Console App
- 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
excel vba excel-vba console console-application
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
add a comment |
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
add a comment |
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
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
add a comment |
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
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
add a comment |
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
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
add a comment |
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
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
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
add a comment |
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
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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