Introduction to automation

Every computer user does some kind of daily work. For example, you may need to do something on your computer at a certain time, or as a financial trader you may need to check the value of a particular stock or product every minute. If only these tasks were automated, it would save us a lot of time and effort, wouldn’t it?

There are several tools on the market today to automate these tasks. One of those programming languages is Visual Basic for Applications. It is event-driven and can work wonders when used with one of our MS Office (host) applications. It also has a macro recording function that allows beginners to create their own projects or codes.

Short call

Since we use the VBA code, there is a possibility for user intervention to continue the code. It can be a user input, a mouse click on an unexpected pop-up window or an OK button. In many of these situations it is difficult to trace and automate the properties properly.

One solution: Transmission of messages

The VBA offers us a solution for these problems with the SendKeys method. This statement simulates the input of text on the keyboard during runtime.

Syntax for using the SendKeys method:

alt=Send buttons in intellectual data – original width=403 original height of data=54 data-ezsrc=http://server.digimetriq.com/wp-content/uploads/2020/11/What-are-SendKeys-in-VBA.png data-ez= /> Screenshot of the displayed intellectual data for the SendKeys method.

SendKeys, [ ]

Where’s that?

Wait is a boolean value that indicates standby mode.

If the value is true, the check waits for the key to be sent and at the end of the action.

If the value is set to False, the controller switches to the next printout in the code immediately after pressing the button.

A line or keystroke is a character or a group of characters to be typed at a given time. This parameter can also be the equivalent of an ASCII key, as shown in the table below. The first three keys Shift, Ctrl and Alt can be used with the corresponding codes, regardless of the key combination used. For example:

  1. Ctrl + C to copy
  2. Ctrl + V for pasta
no Key Code
1 SHIFT “+”
2 CTRL “^”
3 ALT “%”
4 Backspace key {Backspace}, {BKSP}, {BS}
5 Pause Break.
6 Includes the blockage {CapsLock}
7 delete Remove, remove.
8 Down arrow
9 at the end of
10 Access. _
11 Escape {Esc}
12 Help [help]
13 Homepage The house.
14 Fill in here.
15 Left arrow On the left…
16 Cipher lock {NumLock}
17 Scroll down {Pgdn}
18 Page view {Pgup}
19 Pressure screen {PrtSc}
20 right arrow That’s right.
21 Roller lock {\an5}
22 Rooms {Spaces} or try it.
23 tab {Tab}
24 Up arrow {High}
25 F1 TOT F16 {F1} … {F16}
26 WHERE WHERE
27 FALSE FALSE

This replaces manual input or key-pressing. Sending data entered on the keyboard in an open and active window is certainly a possible option, but it should only be considered as an alternative method. It is recommended to use it only if another form of communication is not supported by the question. An example of such an application is Notepad or Notepad++.

Some simple examples

  1. This program opens Notepad, selects Hello World! and saves the file named TRIAL without changing the default path.

Public Sub NotePad_Test()
Explanation of variable
Dim varRet as variant

Booting a variable, i.e. opening a notepad application from Windows
varRet = Shell (NotePad.exe, vbNormalFocus)

Activate this log
Activate the varRet

Send the keyboard data to the
Application.SendKeys Hello World! notebook on the right side

Press the Enter key with the P.T.T. key. This is for the new line
Application.SendKeys ~, True.

It sends (Alt + F + A), which is a shortcut (File > Save as) .
It is followed by the file name TRIAL and ten hits on entry (corresponding to pressing the save button).
Attachment. Shipping buttons %FATRIAL~, True
End Sub

2. With this program you can change a cell using one of the predefined function keys.

Sub Edit_a_cell()
‘ Select a cell on sheet
Range(A1).Select

Edit cell
Application.SendKeys {F2}
End Sub

3. This program adds a line above the line selected with the SendKeys method.

Subcategory Row_Insertion()
‘Select the second row of the active workbook
ThisWorkbook.ActiveSheet.Rows(2:2).Select

The shortest way to insert a new line is Alt+I+R. Try this with the transmission keys
Application.SendKeys %ir
End Sub

Ignition key errors

Here is an example of the failure of the Sendkeys method. Here I try to copy and paste the value of the cell into another adjacent cell using the SendKeys method. But I have some problems and this method doesn’t give me good results.

But I can do that simply by setting values. The same is clearly explained in the video below.

Under copy_paste()

Select the cell to be copied and wait until it is selected
Range (A1). Select request
. Wait (Now() + time value (00:00:05)).

copy it with SendKeys and wait for it to be copied by
Application.SendKeys ^c, True
Application.Wait (Now() + TimeValue(00:00:05))

Select a cell to insert and wait for it to receive the selected range
Range(B1).select
Application.wait (Now() + Time Value(00:00:05)).

plug him in with the shipping keys and wait until he’s plugged in.
Application.SendKeys ^v, True
Application.Wait (Now() + TimeValue(00:00:05)).

A simple command solves problem
Field(b1). Value = Range (a1).

Last sub-heading

Take a good look at the video below to understand and try the above examples.

In the above examples and videos, you may have noticed that despite the long wait after each line of code, the copy and paste actions do not work as expected. The same was achieved in no time with a single line of code. This is a bug in the SendKeys method.

Conclusion

SendKeys is a good alternative for cases where your window does not respond to the language of the code or does not support the interaction with the user interface, but the work still has to be done. This partly corresponds to manual work and therefore VBA gives us an advantage if we use this method.

SendKeys may run in a different window if there are unexpected pop-ups or network problems. It is therefore preferable to perform the automation with SendKeys in the presence of the user – also known as visited automation. This will help to detect and address unexpected interruptions in the implementation of the programme and ensure that the final result is in line with the objective.

excel vba sendkeys to internet explorer,vba sendkeys not working windows 10,excel vba detect keypress,sendkeys vbs,sendkeys spacebar,sendkeys selenium vba,sendkeys powershell,sendkeys windows key,windows 10 sendkeys alternative,sendkeys vb6,vba sendkeys alt tab,vba sendkeys ctrl+v,vba sendkeys ctrl+p,application sendkeys s,excel vba sendkeys to active window,sendkeys vba not working,sendkeys macro access,sendkeys wait time,excel macro sendkeys to another application,sending keystrokes to another application vba,simulate typing vba,vba sendkeys to notepad,vba sendkeys special characters,vba selenium sendkeys enter,sendkeys fx,vb net sendkeys,vba sendkeys to another application,excel vba sendkeys (enter not working),ms access vba page down,sendkeys alt tab,vba sendkeys multiple,vba sendkeys ctrl+c,sendkeys example,sendkeys wait vba,vba code for enter key,vba sendkeys windows key

You May Also Like

🥇 Calculate the Cost of a Product in Excel  Step by Step Guide ▷ 2020

If you want to sell a product or offer a service to…

🥇 MICROSOFT POWERPOINT  What is it? + Alternatives ▷ 2020

One of the advantages of using Office software packages is that you…

Pytorch Image Augmentation using Transforms.

In-depth learning models generally require a lot of data for learning. In…

Fix: Google Photos not backing up on iPhone

For many iPhone users, Google Photos remains the first choice, even though…