×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

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

Jobs

Call a Macro from a Macro

Call a Macro from a Macro

Call a Macro from a Macro

(OP)
Sometimes my macros are too long. Is there a way I can call a macro from a macro? Or is there a way I can run a macro without running into errors because it's too long?

RE: Call a Macro from a Macro

this works for me; just run Sub Main

CODE

Declare Sub Macro1()
Declare Sub Macro2()

Sub Main
    
    Call Macro1
    Call Macro2
    
End Sub


Sub Macro1()
    
    msgbox "Hello, this is Macro1"
   
End Sub

Sub Macro2()

    msgbox "Hello, this is Macro2"

End Sub 

RE: Call a Macro from a Macro

I need help along the lines of the OP.

I'm having a hard time writing (not a programmer unfortunately or too familiar wth VB) a macro in Attachmate or VBA that's sole purpose is to run 3 other macro's. Example, I want to run "Multiple Macro File" in Attachmate that will run the following macro's in order, but not at the exact same time: Trouble1, Trouble2, and Trouble3. All three "Trouble" files are macro's that pull information from Attachmate and post into Excel. Each "Trouble" macro runs fine independently, but I'd like to combine them into one file for non-tech related employees to use.

Also, does hosting those 3 macro's on a specific network drive versus the computer harddrive make a difference.

Thank you very much.

RE: Call a Macro from a Macro

(OP)
If you follow the above suggestion from remy988, your 'main' macro will only run the macros in the order you list them.
You'll have one macro, say it's called 'CallMacR.ebm' Then you'll have each separate mac - Trbl1.ebm, Trbl2.ebm etc..

CallMacR.ebm will call Trbl1.ebm first (if that's the one you list first) and then Trbl2.ebm.

Looks kind of like this:

' Global variable declarations
Global g_HostSettleTime%
Dim rc%, row%, MaxColumns%, MaxRows%, filenum%
Dim Screenbuf$, linebuf$, FileName$
Dim System As Object
Dim Session as Object
'$Include: "H:\Test Scripts\Testing\Macros\(01) REGRESSION - NEW \Include\test1.EBH"
'$Include: "H:\Test Scripts\Testing\Macros\(01) REGRESSION - NEW \Include\test2.EBH"
'$Include: "H:\Test Scripts\Testing\Macros\(01) REGRESSION - NEW \Include\test3.EBH"
Sub Main()
'--------------------------------------------------------------------------------
' Get the main system object
Dim Sessions As Object
Dim System As Object
label1:
Set System = CreateObject("EXTRA.System") ' Gets the system object
If (System is Nothing) Then
Msgbox "Could not create the EXTRA System object. Stopping macro playback."
STOP
End If
Set Sessions = System.Sessions

If (Sessions is Nothing) Then
Msgbox "Could not create the Sessions collection object. Stopping macro playback."
STOP
End If
'--------------------------------------------------------------------------------
' Set the default wait timeout value
g_HostSettleTime = 600 ' milliseconds

OldSystemTimeout& = System.TimeoutValue
If (g_HostSettleTime > OldSystemTimeout) Then
System.TimeoutValue = g_HostSettleTime
End If

' Get the necessary Session Object
Dim Sess0 As Object
Set Sess0 = System.ActiveSession
Set Session = System.ActiveSession

If (Sess0 is Nothing) Then
Msgbox "Could not create the Session object. Stopping macro playback."
STOP
End If
If Not Sess0.Visible Then Sess0.Visible = TRUE
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)

label:
' This section of code contains the recorded events
'--------------------------------------------------------------------------------------------------

Sess0.Screen.Sendkeys("<Clear>")
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
Sess0.Screen.Sendkeys("td<Enter>")
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)

test1
test2
test3

End Sub
-------------------------------------------------------------------------------------------------------THEN

TEST1.ebm - will have your normal macro stuff in it.

Hope that helps.

I'm not a programmer either. But this worked really well for me.

RE: Call a Macro from a Macro

I think the problem afortuna is running into is the macros are too long. I don't think declaring the subroutines inside the "Main" macro will work in this case. He, and I have been trying to get the $Include statement to work, but to no avail.

RE: Call a Macro from a Macro

Trouble is, that calls thru your emulator are performed ASYNCHRONOUSLY in the host system. Your code must recognizes this disconnect and wait until the host system returns data to the emulator before proceeding to the next step.

RE: Call a Macro from a Macro

afortuna98/DustoBOE

Quote:

have been trying to get the $Include statement to work, but to no avail.

what's wrong? how is it not working?

just to be sure, have you tried a shorter code with the $Include statement? I'm just trying to understand.

RE: Call a Macro from a Macro

The $Include works on my system. I can make work with very simple commands such as msgbox pop-ups. So the problem is in the code. I'm not familiar with header files at all. In fact this is the first time I have heard of such a thing so please forgive me.

I'm sure the problem is with the syntax I am using in the .ebh file.

A couple of questions if I may.

1. Can I just record a macro and rename the .ebm to .ebh?

2. In the header file, do I need to have this section?:

CODE -->

' Get the main system object
	Dim Sessions As Object
	Dim System As Object
	Set System = CreateObject("EXTRA.System")	' Gets the system object
	If (System is Nothing) Then
		Msgbox "Could not create the EXTRA System object.  Stopping macro playback."
		STOP
	End If
	Set Sessions = System.Sessions

	If (Sessions is Nothing) Then
		Msgbox "Could not create the Sessions collection object.  Stopping macro playback."
		STOP
	End If
'--------------------------------------------------------------------------------
' Set the default wait timeout value
	g_HostSettleTime = 500		' milliseconds

	OldSystemTimeout& = System.TimeoutValue
	If (g_HostSettleTime > OldSystemTimeout) Then
		System.TimeoutValue = g_HostSettleTime
	End If

' Get the necessary Session Object
	Dim Sess0 As Object
	Set Sess0 = System.ActiveSession
	If (Sess0 is Nothing) Then
		Msgbox "Could not create the Session object.  Stopping macro playback."
		STOP
	End If
	If Not Sess0.Visible Then Sess0.Visible = TRUE
	Sess0.Screen.WaitHostQuiet(g_HostSettleTime) 

3. What would a header file look like that sends a few keys to the current session?


Thanks for your help fellas.

RE: Call a Macro from a Macro

(OP)
DustoBOE,
You should just try the things you're not sure will work. If you save with a .ebh extension and it doesn't work, then ....!
This is how I learned... for the most part.

J

RE: Call a Macro from a Macro

when you're in the macro editor, click on new and you will see a choice for macro or header...
this is where the header is created.

as an aside, have you tried what i had posted earlier, instead of using include?

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