From iMacros
Jump to navigation Jump to search

Instead of having the script call a locally saved macro, it can also "send" macro code directly to an iMacros instance.

Important: Each iimPlay run resets all settings and value from the previous iimPlay run. This means that you should not use one iimPlay per line, but first concatenate all commands and then send them to iMacros via the iimPlay command (as shown in this example). The browser context is preserved between different iimPlay, so one macro can continue where the previous one stopped. Only iMacros internal settings (SET command) are reset between different iimPlay.

Tip: To convert text macros (iim files) into inline code use the iMacros Editor Code Generator feature.

' iMacros Send-Macro-Code Script
' (c) Ipswitch Inc. 

Option Explicit
Dim iim1, iret

MsgBox ("This example script uses NO macros, but sends the macro code directly.")

set iim1= CreateObject ("imacros")
iret = iim1.iimOpen("-ng")

Dim MyMacroCode

MyMacroCode = "TAB T=1" + vbNewLine    
MyMacroCode = MyMacroCode+"TAB CLOSEALLOTHERS" + vbNewLine  
MyMacroCode = MyMacroCode+"URL GOTO=" + vbNewLine
MyMacroCode = MyMacroCode+"WAIT SECONDS=3" + vbNewLine 
MyMacroCode = MyMacroCode+"URL GOTO="

'Tip: Use the iMacros Editor Code Generator feature
'to convert your iMacros macros into some scripting/programming language code. 

iret = iim1.iimDisplay("Start demo")
'Run the first macro
iret = iim1.iimPlayCode(MyMacroCode)
if iret < 0 Then
   MsgBox "Macro#1: Error Code: "+cstr(iret) + VbCrLf + "Error Text: "+iim1. iimGetErrorText()
End If

'Run the second macro (one line only)
iret = iim1.iimPlayCode("URL GOTO=")
If iret < 0 Then
      MsgBox "Macro#2: Error Code: "+cstr(iret) + VbCrLf + "Error Text: "+iim1. iimGetErrorText()
End If

iret = iim1.iimDisplay("Script completed.")

MsgBox "Close iMacros browser"

iret = iim1.iimClose