Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Macro's - a General query/lesson 1

Status
Not open for further replies.

andy7172289

Technical User
Aug 16, 2016
19
GB
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,
Andrew
 
If the application don't expose automation, interaction is limited. Notepad from excel example:
Code:
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.

combo
 
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!
 
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?
 
the system I want to use it for.

FYI...

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.

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
 
the code identifies the notepad as a number, right?
Shell returns process ID (PID), that you can see in task manager details tab.

combo
 
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.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top