Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Macro's - a General query/lesson

Macro's - a General query/lesson

Macro's - a General query/lesson

Morning all,

I have been writing rudimentary macros for excel for about a year now but I've heard of a way to write macro's which will open other programms and perform keystrokes within a system to perform very manual processes. An example would be having to press the arrow key down, type "S", press enter - REPEAT.

Can anyone give me some example code of what this might look like?
Is this something I'd have to design and run from Excel, despite it's true purpose to be to use another software?

Any help with this would be greatly appreciated.

Thanks in advance,

RE: Macro's - a General query/lesson

If the application don't expose automation, interaction is limited. Notepad from excel example:


Sub WorkWithNotepad()
    Dim IDnotepad As Double ' to identify application with AppActivate
    IDnotepad = Shell("Notepad", vbMaximizedFocus)
    MsgBox IDnotepad, vbOKOnly, "Notepad ID:"
    AppActivate IDnotepad
    SendKeys "Notepad text from excel."
    SendKeys "{ENTER}"
    SendKeys "~" ' other ENTER key code
    SendKeys "This is third line."
    MsgBox "Saving document, prompt for file name if new", vbOKOnly, "Notepad action"
    AppActivate IDnotepad
    SendKeys "^s" ' display save dialog or save existing document
End Sub 
See SendKeys help for full keys codes.


RE: Macro's - a General query/lesson

Thanks for your response, I'll look into playing about with something like notepad first before moving onto the system I want to use it for. Thanks again!

RE: Macro's - a General query/lesson

Right so the beginning of the code identifies the notepad as a number, right? I assume this is important when needed to identify the same app when switching between applications?

I'm trying to move to another application which is already open with someone's log on already entered. Another side note, is the system is old, and will require me to use the enter key from the number pad enter, not the return key from the enter closest to the letters - if that makes sense?

RE: Macro's - a General query/lesson


the system I want to use it for.


For some of those other systems, there may be other forums as well. For instance there are two forums for Attachmate terminal emulators. These have their own object model and coding distinctives.


glassesJust traded in my OLD subtlety...
for a NUance!tongue

RE: Macro's - a General query/lesson


the code identifies the notepad as a number, right?
Shell returns process ID (PID), that you can see in task manager details tab.


RE: Macro's - a General query/lesson

Or you might like to have a look at AutoIt or AutoHotkey

RE: Macro's - a General query/lesson

The thing is, it's a company PC and I'm unable to install new software. Just to clarify, when I say old system, I mean to say an application that is old. Apologies for the poor terminology!

I'm running Windows 7, so using a macro should work.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close