VBA & Macro Problems

Fix VBA SendKeys Entering 'Tab' Instead of Name in PDF Form

Adam DavisAdam Davis Nov 2, 2026 868 views

Question details

The user needs to correct a VBA script that types the literal word "Tab" instead of executing a Tab keystroke when filling out a PDF form, and also requires a method to dynamically identify the most recently entered row in the Excel worksheet.

Fix VBA SendKeys Entering 'Tab' Instead of a Name in a PDF Form
Product
Excel VBA
Device & OS
not provided
Scenario
Automating data transfer from an Excel worksheet to a PDF form using the VBA SendKeys method.
Observed behavior
The script sends the text string "Tab" to the form field rather than moving to the next field, and fails to automatically locate the latest record in the spreadsheet.
Before you start

Ensure you have the target PDF form open and save a backup copy of your Excel workbook before modifying the VBA macro code.

Solution 1Recommended

Use Curly Braces for Special Keys and the End(xlUp) Method

Correct the SendKeys parameter to use curly braces for special keystrokes and utilize a standard VBA technique to find the last populated row in a specific column.

In VBA, the SendKeys method requires special keyboard keys like Tab, Enter, and Backspace to be wrapped in curly braces {}. If you use parentheses () or no brackets at all, the application will interpret the input as literal text characters.

To reliably pull data from the most recently entered row, you should avoid hardcoding row numbers. Instead, use the End(xlUp) method to count upward from the bottom of the sheet to find the last active row dynamically.

1
Open the Visual Basic Editor

Press Alt + F11 in your Excel workbook to open the Visual Basic Editor (VBE) and locate your macro module.

2
Correct the SendKeys syntax

Find the line using the SendKeys command. Change the syntax to use curly braces. For example, change Application.SendKeys "(Tab)" to Application.SendKeys "{Tab}", True.

3
Identify the last used row

Add the following code snippet before your data retrieval line: Dim lastRow As Long, then lastRow = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row (replace 'A' with your target column letter).

4
Retrieve the latest record

Update your variable assignment to fetch the value from the newly identified row: Dim strName As String, then strName = ActiveSheet.Cells(lastRow, "A").Value.

Use Curly Braces for Special Keys and the End(xlUp) Method
Tip: Ensuring Window Focus: Include the AppActivate command and an Application.Wait pause before your SendKeys line to ensure the PDF application has successfully gained focus before the keystrokes are sent.
WPS Office Macros Support

Automate Data Entry Seamlessly with WPS Spreadsheet

WPS Office Spreadsheet provides excellent compatibility with Excel VBA, allowing you to run, edit, and troubleshoot SendKeys macros without needing to completely rewrite your original code.

  1. 1. Open your macro file in WPS: Launch WPS Spreadsheet and open your existing .xlsm or .xlsb workbook.
  2. 2. Access the VBA Editor: Navigate to the 'Tools' tab on the ribbon and click 'Macro' to open the Visual Basic Editor.
  3. 3. Update your code: Locate your SendKeys command, ensure special keys use braces like "{Tab}", and add your last-row calculation script.
  4. 4. Run your macro: Save your module and execute the macro to seamlessly transfer the latest spreadsheet data to your PDF forms.
Fully compatible with Microsoft Excel (.xlsm) macro-enabled filesAdvanced built-in VBA editor to quickly debug syntax errors like SendKeysLightweight application that executes repetitive macros quicklyFree to use with a familiar, easy-to-navigate interface
microsoft office alternative - wps office

Frequently Asked Questions

Why does VBA SendKeys type the name of the key instead of pressing it?

This happens when the key name is not enclosed in curly braces. VBA treats standard text enclosed in quotes as a literal string. You must use curly braces, such as {Tab} or {Enter}, to instruct SendKeys to simulate the actual keystroke.

How can I send a combination of keys like Alt+Tab in VBA?

You can combine keystrokes using special modifier characters. Use % for Alt, ^ for Ctrl, and + for Shift. To simulate pressing Alt+Tab, you would write Application.SendKeys "%({Tab})".

Why is my SendKeys macro sending data to the wrong application?

The SendKeys method interacts with whichever window is currently active on your operating system. If your macro loses focus on the intended PDF before executing, it will type into another active program. Always use the AppActivate statement to bring the correct window to the foreground first.