SendKeys - VBA Macros

BetterSolutions.comBetterSolutions.com
  • Resources
  • Microsoft Office Excel
  • Microsoft Office Word
  • C# Programming
  • JavaScript Programming
  • Add-ins
  • Office Add-ins for Excel
  • Office Add-ins for Word
  • Consultancy
  • Macros, Templates and EUDAs
  • TypeScript and JavaScript
  • Development
  • Office JS Add-ins and Scripts
  • End User Programming
  • Support
  • VSTO and .NET Migration
  • Troubleshooting
  • Training
  • Microsoft 365 Integration
  • Contact Us Today for a FREE Consultation
  • Excel
      • Add-ins
      • Best Practices
      • Cells Ranges
      • Charts
      • Conditional Format
      • Data Analysis
      • Data Validation
      • Dates Times
      • Search Excel ...
      • Functions
      • User Defined
      • Formulas
      • Formatting
      • Illustrations
      • Importing
      • Layout
      • Macros
      • Our Services ...
      • Named Ranges
      • Options
      • Pivot Tables
      • Power Automate
      • Protection
      • Python
      • Reviewing
      • Ribbon
      • Find Add-ins ...
      • Rows Columns
      • Shortcut Keys
      • Tables
      • Templates
      • Track Changes
      • Workbooks
      • Worksheets
      • XML
      • Contact Us ...
  • Word
      • Add-ins
      • Bookmarks
      • Building Blocks
      • Bullets
      • Characters
      • Charts
      • Content Controls
      • Design
      • Search Word ...
      • Documents
      • Fields
      • Illustrations
      • Importing
      • Layout
      • Macros
      • Mailings
      • Numbering
      • Our Services ...
      • Options
      • Outlines
      • Pages
      • Paragraphs
      • Protection
      • References
      • Reviewing
      • Ribbon
      • Find Add-ins ...
      • Sections
      • Shortcut Keys
      • Styles
      • Tables
      • Templates
      • Text Boxes
      • Track Changes
      • XML
      • Contact Us ...
  • PowerPoint
      • Add-ins
      • Animation
      • Bullets
      • Characters
      • Charts
      • Design
      • Handouts
      • Illustrations
      • Search PowerPoint ...
      • Importing
      • Layout
      • Macros
      • Notes
      • Numbering
      • Options
      • Outlines
      • Paragraphs
      • Our Services ...
      • Presentations
      • Protection
      • References
      • Reviewing
      • Ribbon
      • Sections
      • Shortcut Keys
      • Slide Show
      • Find Add-ins ...
      • Slides
      • Tables
      • Templates
      • Text Boxes
      • Track Changes
      • Transitions
      • Video
      • XML
      • Contact Us ...
  • Outlook
      • Add-ins
      • Address Book
      • Alerts
      • Appointments
      • Calendar
      • Contacts
      • Events
      • Exchange
      • Search Outlook ...
      • Folders
      • Forms
      • Groups
      • HTML
      • Illustrations
      • Importing
      • Journal
      • Macros
      • Our Services ...
      • Mail
      • Meetings
      • Notes
      • OneDrive
      • OneNote
      • Options
      • People
      • Proofing
      • Find Add-ins ...
      • Ribbon
      • Rules
      • Search
      • SharePoint
      • Shortcut Keys
      • Tasks
      • Web Client
      • XML
      • Contact Us ...
  • VBA
      • Add-ins
      • Arrays
      • Best Practices
      • Class Modules
      • Code Snippets
      • Collections
      • Controls
      • Databases
      • Search VBA ...
      • Data Types
      • Dates Times
      • Debugging
      • Enumerations
      • Error Handling
      • Events
      • Files Directories
      • Functions
      • Our Services ...
      • Macros
      • MsgBox
      • Numbers
      • Options
      • References
      • Ribbon
      • Shortcut Keys
      • SQL
      • Find Add-ins ...
      • Strings
      • Subroutines
      • Syntax
      • Userforms
      • Variables
      • Visual Basic Editor
      • Web Interaction
      • XML
      • Contact Us ...
  • C#
      • .NET Library
      • Arrays
      • Best Practices
      • Classes
      • Collections
      • Databases
      • Data Types
      • Dates Times
      • Search C# ...
      • Debugging
      • Excel Interop
      • Error Handling
      • Files Directories
      • Generics
      • Interfaces
      • MessageBox
      • Numbers
      • Our Services ...
      • Projects
      • Serialization
      • Strings
      • Structures
      • Syntax
      • Threading
      • Variables
      • VBA Migration
      • Find Add-ins ...
      • Visual Studio
      • VSTO Add-ins
      • Web Add-ins
      • Web Development
      • Web Services
      • Windows Forms
      • WPF Forms
      • XML
      • Contact Us ...
  • JS
      • Arrays
      • Custom Functions
      • Data Types
      • Dates Times
      • Debugging
      • Dialog Boxes
      • Error Handling
      • Excel API
      • Search JavaScript ...
      • Express Backend
      • Fluent UI
      • Functions
      • HTML Pages
      • Microsoft Graph
      • Node JS Runtime
      • Numbers
      • Objects
      • Our Services ...
      • Office Add-ins
      • Office Events
      • Office Manifest
      • Office Scripts
      • Outlook API
      • PowerPoint API
      • React Library
      • Ribbon Commands
      • Find Add-ins ...
      • Strings
      • Syntax
      • Task Panes
      • TypeScript
      • Variables
      • Visual Studio Code
      • Word API
      • Yeoman Generator
      • Contact Us ...
PreviousNextVBA > Macros
  • VBA Programming
  • Macros
  • Getting Started
  • User FAQs ...
  • Best Practices ...
  • Troubleshooting
  • Macro Settings ...
  • Recording
  • Running ...
  • Code Modules ...
  • Subroutines ...
  • Functions ...
  • Arguments ...
  • ByVal or ByRef ...
  • Application. ...
  • Region and Language ...
  • Colours ...
  • Updates ...
  • Registry
  • Windows API
  • advapi32.dll
  • kernel32.dll
  • shell32.dll
  • user32.dll
  • SendKeys
  • Project Is Unviewable
  • Readiness ToolKit
  • Code Snippets ...
  • Updated: 01 December 2025
  • 01 December 2025
SendKeys

This is a method for sending one or more keystrokes to the active window.This should only be used as a last resort as it is not 100% secure and relies on the user not interrupting the macro.SendKeys allows you to send keystrokes to the currently active window and is often used to control applications that do not support any other form of communication.An example of such an application is NotePad.

Simple Example

This example opens NotePad and sends a line of data before saving the file.

Public Sub OpenNotePad Dim vReturn As Variant vReturn = Shell("NotePad.exe", vbNormalFocus) AppActivate vReturn Application.SendKeys "Copy Data.xls C:\", True 'this sends an Enter Application.SendKeys "~", True 'this sends an (Alt + F + A) to perform a (File > Save As) and then enters the filename "BATCH" and presses Enter Application.SendKeys "%FABATCH~", True End Sub

Multiple Keys

You can abbreviate sending the same key several times by appending a number inside the bracketsThis has not been tested yet !!

Application.SendKeys "{Up 6}"

This sends a Ctrl + F1

Application.SendKeys "^{F1}"

Example of joined up

Application.SendKeys "{TAB}{TAB}"

Potential Problems

When using SendKeys you often find that not all the keys sent reach the dialog box although sending all the keys at once does not make a difference.

Application.SendKeys "{Esc}"

Enter simulate Tab

Make the Enter simulate the Tab key

Sub Form_KeyPress (keyAscii as integer) If KeyAscii = vbKeyReturn Then SendKeys "{TAB}" KeyAscii = 0 End If End Sub

Reference Table

SHIFT"+"
CTRL"^"
ALT"%"
Backspace{Backspace}, {BS}, {BKSP}
Break{Break}
Caps Lock{CapsLock}
Delete{Delete}, {Del}
Down Arrow{Down}
End{End}
Enter{Enter}, ~
Escape{Esc}
Help{Help}
Home{Home}
Insert{Insert}, {Ins}
Left Arrow{Left}
Num Lock{NumLock}
Page Down{Pgdn}
Page Up{Pgup}
Print Screen{PrtSc}
Right Arrow{Right}
Scroll Lock{ScrollLock}
Spacebar{Space} or try " "
Tab{Tab}
Up Arrow{Up}
F1 - F16{F1} .. {F16}
TrueTrue
FalseFalse
© 2025 Better Solutions Limited. All Rights Reserved. © 2025 Better Solutions Limited TopPrevNext

Từ khóa » Visual Basic Sendkeys Tab