0

I have a C# application that I manually run every morning that functions based off of the values that I select from the Institution Name column. Any values that are selected when I press the Put Files button will push files from a folder into a designated folder, any files I select when I press the Get Files button will retrieve files from a designated folder and place them into an assigned folder. I am currently trying to automate this process by using VBA. For a high-level overview of what I would need to make this possible, I would need code to:

  • Automatically open my C# application (Completed)
  • Code to select the values (Incomplete)
  • Code to wait for the C# application to finish running before continuing with the rest of the macro (Completed)

Since the certain values that will be pressed for each run of Put Files and Get Files will be fixed, I was wondering if there was a way to get VBA to automatically select the values for myself once I run the code since it won't vary. Thanks.

enter image description here

Edit:

The below code is what I use to locate and open the C# application. As I now understand it thanks to Christopher Hamkins, I will need to access WinForm as an object and manipulate it in order to highlight the necessary values.

Dim fileName As Variant
Dim filePath As String
Dim fso As Object
Dim sfile As String
    Set fso = CreateObject("shell.application")


filePath = "C:\Dropbox (###)\###\###\###\"
fileName = Dir(MyPath & "### UI*")

If fileName <> "" Then
    fso.Open (filePath & fileName)
End If
bgado
  • 41
  • 6
  • 2
    So, you're trying to write VBA code that will move your mouse and click on form elements from your c# program? If correct, that seems like a very contrived way of accomplishing the task. Why not just write the entire process in a single programming language which runs headless on a schedule? – gunr2171 Nov 08 '21 at 15:48
  • Yes that is what my goal is. The reasoning behind me using VBA is that I am not the developer of the C# application, nor do I have any background in C# which is why I am turning to VBA which I do have more experience in, however not in this realm of interacting with a separate app. – bgado Nov 08 '21 at 15:54
  • So why not do everything that the C# app is doing in VBA? – gunr2171 Nov 08 '21 at 15:54
  • Does this help: https://myengineeringworld.net/2020/01/call-csharp-console-app-vba.html – Christopher Hamkins Nov 08 '21 at 15:57
  • Hi Christopher, yes I have already referenced this article and found portions of it useful for my end goal, however not this particular question. The C# application in the example doesn't appear to have any values requiring selection, it just runs straight through, whereas I need to be able to select/highlight values from the C# application and not simply call it. – bgado Nov 08 '21 at 16:06
  • It might help to get answers if you would add the key parts of your code to your question. You'll somehow need to get access to the WinForm as an object to be able to manipulate it and call its button click events. – Christopher Hamkins Nov 08 '21 at 16:18
  • Gotcha, thanks Christopher, I will update shortly. – bgado Nov 08 '21 at 16:42
  • 1
    Your c# is a console app (*.exe), correct? I'm thinking this won't be possible. https://stackoverflow.com/questions/41119638/add-a-net-exe-as-a-vba-reference-within-excel-for-com-interop explains that you can't get references in an exe within VBA. The c# output has to be a dll that is "COM-visible" and registered for COM-Interop. That is easy if you have control over the c# application, but it sounds like you don't. Also relevant: https://social.msdn.microsoft.com/Forums/en-US/62c819fe-338a-4792-b5d1-c8e9ebf55e0b/how-is-possible-to-add-a-dll-file-as-reference-in-a-vba-project?forum=netfxbcl – Christopher Hamkins Nov 09 '21 at 10:41
  • 1
    Maybe this will help, though https://stackoverflow.com/questions/22714374/how-to-programmatically-click-the-mouse-in-another-program-when-this-code-doesn – Christopher Hamkins Nov 09 '21 at 13:03
  • Correct it is an .exe -- I appreciate your assistance, thanks. – bgado Nov 10 '21 at 19:22

0 Answers0