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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Call a Macro from a Macro

Status
Not open for further replies.

jonesy1

Technical User
Feb 20, 2012
31
US
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?
 
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
 
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.
 
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.
 
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.
 
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.
 
afortuna98/DustoBOE

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.

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

Part and Inventory Search

Sponsor

Back
Top