Copy and paste excell cell data to another software with sendkeys or API

SofianeR

New Member
Joined
May 12, 2022
Messages
9
Office Version
  1. 2019
Platform
  1. Windows
Hello,
I have to take data from an excel file that contains mostly int or float that correspond to electrical engineering simulations and paste them into a software that is called Cymcap to run these simulations. Each line of the excel file is a simulation and sometimes there are hundreds of lines with different parameters each time so for the moment we are forced to enter them by hand but it's not very efficient. I have to make a script that will copy all the data from each cell of the excel file and paste them into the Cymcap software.
2 big problems: 1- the cymcap software doesn't accept scripts so I can't add a script in the software and it doesn't accept the excel and txt files to upload them.
2- I thought of making a clickbot that could automate the copy and paste of each excel cell to the right cell in cymcap but it will just work for my computer because the resolution and screen size change (x and y position change hardcode).
I could add a mouse and keyboard recorder in the script so that the person copy paste the first line of excel with all the data and loop it for all the other lines.
Or i can use the sendkey or WinAPI method but i am not really familiair with those.
Thank you so much for your help!
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Hard to answer without knowing your program.
1. At least the program must be able to be used with the keyboard alone. (Using tab, arrow key, enter...)
2. The number and order of the fields to be filled must be constant or at least clearly predictable.
3. There should be no unexpected pop-ups, queries, or other interruptions.
 
Upvote 0
# importing time and threading
import time
import threading
from pynput.mouse import Button, Controller

# pynput.keyboard is used to watch events of
# keyboard for start and stop of auto-clicker
from pynput.keyboard import Listener, KeyCode


# four variables are created to
# control the auto-clicker
delay = 0.001
button = Button.right
start_stop_key = KeyCode(char='a')
stop_key = KeyCode(char='b')

# threading.Thread is used
# to control clicks
class ClickMouse(threading.Thread):

# delay and button is passed in class
# to check execution of auto-clicker
def __init__(self, delay, button):
super(ClickMouse, self).__init__()
self.delay = delay
self.button = button
self.running = False
self.program_running = True

def start_clicking(self):
self.running = True

def stop_clicking(self):
self.running = False

def exit(self):
self.stop_clicking()
self.program_running = False

# method to check and run loop until
# it is true another loop will check
# if it is set to true or not,
# for mouse click it set to button
# and delay.
def run(self):
while self.program_running:
while self.running:
mouse.click(self.button)
time.sleep(self.delay)
time.sleep(0.1)


# instance of mouse controller is created
mouse = Controller()
click_thread = ClickMouse(delay, button)
click_thread.start()


# on_press method takes
# key as argument
def on_press(key):

# start_stop_key will stop clicking
# if running flag is set to true
if key == start_stop_key:
if click_thread.running:
click_thread.stop_clicking()
else:
click_thread.start_clicking()

# here exit method is called and when
# key is pressed it terminates auto clicker
elif key == stop_key:
click_thread.exit()
listener.stop()


with Listener(on_press=on_press) as listener:
listener.join()

this is the beginning of my program but as you can see it is a click boat with the mouse movment and not the keyborard movement that i need but i have problems switching it to keyboard keys
 
Upvote 0
Can all data be entered into Cymcap from the keyboard alone?
Most likely the tab moves between fields and buttons. Space or Enter to confirm the action.

First of all, you should try to use Cymcap with the keyboard and enter the data of at least one simulation into it. If you succeed, you can start thinking about using sendkey, if any point requires a mouse, then sendkey is hardly suitable for the task.
 
Upvote 0
yes there is a way that you can to enter all the data of the simulation without using your mouse. But the implementation of sendkey is dangerous and I am not really familiar to me. Do you have any suggestion as to how ans where can i begin or look for information about that method ?
Thank you again for your help
 
Upvote 0

This is one of my old things that I used to fill out some pdf forms.
It’s ugly, and certainly not a good example, but I put it up with a few comments if you want to look it.

VBA Code:
Sub Fill_pdf_TT3()

Dim FilenameOpen As Variant
Dim PathSave As String, PathWeekSave As String, FilenameSave As String
FilenameOpen = "C:\temp\Empty_TT3.pdf"
vPID = Shell("C:\Program Files\Tracker Software\PDF Editor\PDFXEdit.exe " & FilenameOpen, vbNormalFocus) ' Get Pid and activate window



Dim cell As Range, Tiedot As Range
Dim I As Integer, j As Integer
Set Tiedot = ThisWorkbook.ActiveSheet.Range("A1:A22") 'Range where is data to fill form
' Going to first field to fill
Application.Wait (Now + TimeValue("0:00:01") / 2) 'Wait half second
Application.SendKeys ("{TAB}") ' Next field or button
Application.Wait (Now + TimeValue("0:00:01") / 2)'Wait half second
Application.SendKeys ("{TAB}") ' Next field or button
Application.Wait (Now + TimeValue("0:00:01") / 2)'Wait half second


For Each cell In Tiedot ' Filling field start - For Each round is only one filled field
    Application.Wait (Now + TimeValue("0:00:01") / 2)     'Wait half second
    Application.SendKeys cell.Value, True                'Send cell.value to active field"
    Application.Wait (Now + TimeValue("0:00:01") / 2)    'Wait half second
    Application.SendKeys ("{TAB}")                        ' Send tab -keystroke to move next field
    Application.Wait (Now + TimeValue("0:00:01") / 2)    ' Wait half second
Next

PathSave = "M:\pdf\"
PathWeekSave = "23 (2.11.-15.11.)\"
FilenameSave = Tiedot.Cells(2).Value

If Dir("M:\pdf\" & PathWeekSave, vbDirectory) = "" Then
    MkDir "M:\pdf\" & Left(PathWeekSave, Len(PathWeekSave) - 1)
Else
    Debug.Print "Folder found"
    If Dir("M:\pdf\" & PathWeekSave & FilenameSave & ".pdf") = "" Then
        Debug.Print " Ok, No file exist"
    Else
                Exit Sub
    End If
    
    
End If

Application.SendKeys "^+s" 'Ctrl+s = save as

Application.SendKeys PathSave
PathWeekSave = Replace(PathWeekSave, "(", "+8")
PathWeekSave = Replace(PathWeekSave, ")", "+9")
Application.SendKeys PathWeekSave
Application.SendKeys FilenameSave
Application.SendKeys "~" ' =Enter
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,817
Messages
6,181,149
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top