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
10
  • 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? Commented Nov 8, 2021 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. Commented Nov 8, 2021 at 15:54
  • So why not do everything that the C# app is doing in VBA? Commented Nov 8, 2021 at 15:54
  • 1
    Your c# is a console app (*.exe), correct? I'm thinking this won't be possible. stackoverflow.com/questions/41119638/… 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: social.msdn.microsoft.com/Forums/en-US/… Commented Nov 9, 2021 at 10:41
  • 1
    Maybe this will help, though stackoverflow.com/questions/22714374/… Commented Nov 9, 2021 at 13:03

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.