How Do I Get VBA to Work With iMacros?

Discussions and Tech Support related to automating the iMacros Browser or Internet Explorer from any scripting and programming language, such as VBS (WSH), VBA, VB, Perl, Delphi, C# or C++.
Forum rules
Before asking a question or reporting an issue:
1. Please review the list of FAQ's.
2. Use the Google search box (at the top of each forum page) to see if a similar problem or question has already been addressed. This will search the entire contents of the forums as well as the iMacros Wiki.
3. We can respond much faster to your posts if you include the following information:

CLICK HERE FOR IMPORTANT INFORMATION TO INCLUDE IN YOUR POST

Answering your own posts (e.g. attempting to "bump" your topic) drops your topic from the list of unanswered threads, so it may actually receive less views.

How Do I Get VBA to Work With iMacros?

by eryksd on Wed Feb 03, 2016 6:32 pm

Hello,

FCIM:

1. What version of iMacros are you using?
VERSION BUILD=8961227


2. What operating system are you using? (please also specify language)
Windows 7 English (American)

3. Which browser(s) are you using? (include version numbers)
Firefox 43.0.4

4. Do the included demo macros work ok?
Demo macros work, but I couldn't find a way to do what I'm trying to do (more of a general methodology question).

5. If reporting a problem with the Scripting Interface, please also test if the included VBS sample scripts run ok.
No VBS scripts

6. If recording or replay fails on a specific website: Can you please post the URL of the web page and/or the imacro that creates the problem? If you can not post the imacro or login data in the public user forum, please email it to support AT iopus DOT com and mention your forum post in the email.
If specific login info needed, please let me know. But my question pertains to a text box in general, any text box on any website would serve well as an example.

7. Do you encounter the same problem with the iMacros Browser, iMacros for Internet Explorer and iMacros for Firefox? Note: If your question is specifically about iMacros for Firefox or iMacros for Chrome, please use their sub-forums.
Browser works fine, just looking to ask about methodology and whether there is a specific capability of iMacros

----------------------------

Question:

Total noob question, but I can't figure out how to use iMacros from a VBA script.

When I try to use the sample code given on the forums for VBA, I get "Run-time error '429': ActiveX component can't create object", for the line "Set imacros = CreateObject("imacros")"

Am I supposed to define some library or do any other tasks before calling iMacros from a VBA script? I'm new to both iMacros and VBA still.

I have the trial version, downloaded it about 2 weeks ago, I believe it should still be able to have VBA capability
eryksd
 
Posts: 9
Joined: Thu Jan 21, 2016 6:10 pm

Re: How Do I Get VBA to Work With iMacros?

by ybot on Wed Jan 04, 2017 3:51 pm

try:
Code: Select all
Set imacros = GetObject(, "iMacros")

Note "iMacros" is probably case sensitive as the Create and GetObject functions are just VBA calls to native C functions and C is case sensitive.
Also, make sure you've defined imacros as an object first:
Code: Select all
Dim imacros as Object
Set imacros = GetObject(, "iMacros")

But you could probably try CreateObject with the correct case and it might work - or combine the two:
Code: Select all
    Dim iMacros As Object
    On Error GoTo ObjectExistsError
    Set iMacros = CreateObject("iMacros")
    On Error GoTo LaterError
   
Exit Sub
    '--
ObjectExistsError:
   
    Set iMacros = GetObject(, "iMacros")
   
Resume Next
    '--
LaterError:
   
    'Other error handling code goes here
   
Resume Next
ybot
 
Posts: 1
Joined: Wed Jan 04, 2017 2:28 pm

Re: How Do I Get VBA to Work With iMacros?

by Nill2016 on Mon Mar 26, 2018 8:51 am

I tried to use this sample code with firefox, but it appears this error: "Run-time error '429': ActiveX component can not create object". What do you have to do to make it work?
https://wiki.imacros.net/Excel_VBA_Example_Code

Code: Select all
  Option Explicit
   
   Private Sub CommandButton1_Click()
   
   MsgBox "This macro demonstrates how to read data from an Excel sheet and submit this information to a website."
   
   Dim iim1, iret, row, totalrows
   
   Set iim1 = CreateObject("imacros")
   iret = iim1.iimInit
   'Firefox iret = iim1.iimInit ("-fx")
   iret = iim1.iimDisplay("Submitting Data from Excel")
   
   totalrows = ActiveSheet.UsedRange.Rows.Count
   For row = 2 To totalrows
      'Set the variables
      iret = iim1.iimSet("FNAME", Cells(row, 1).Value)
      iret = iim1.iimSet("LNAME", Cells(row, 2).Value)
      iret = iim1.iimSet("ADDRESS", Cells(row, 3).Value)
      iret = iim1.iimSet("CITY", Cells(row, 4).Value)
      iret = iim1.iimSet("ZIP", Cells(row, 5).Value)
      iret = iim1.iimSet("STATE-ID", Cells(row, 6).Value)
      iret = iim1.iimSet("COUNTRY-ID", Cells(row, 7).Value)
      iret = iim1.iimSet("EMAIL", Cells(row, 8).Value)
      'Set the display
      iret = iim1.iimDisplay("Row# " + CStr(row))
      'Run the macro
      'Same macro as in database-2-web.vbs example!
      iret = iim1.iimPlay("wsh-submit-2-web")
      If iret < 0 Then
         MsgBox iim1.iimGetLastError()
      End If
   Next row
   
   iret = iim1.iimDisplay("Submission complete")
   iret = iim1.iimExit
   
   End Sub



Code: Select all
VERSION BUILD=700705 
 TAB T=1     
 TAB CLOSEALLOTHERS     
 URL GOTO=http://www.iopus.com/imacros/demo/v6/f2/automatic-data-entry.asp     
 TAG POS=1 TYPE=INPUT:TEXT FORM=NAME:WebDataEntry ATTR=NAME:FNAME CONTENT={{FNAME}}
 TAG POS=1 TYPE=INPUT:TEXT FORM=NAME:WebDataEntry ATTR=NAME:LNAME CONTENT={{LNAME}}
 TAG POS=1 TYPE=INPUT:TEXT FORM=NAME:WebDataEntry ATTR=NAME:ADDRESS CONTENT={{ADDRESS}}
 TAG POS=1 TYPE=INPUT:TEXT FORM=NAME:WebDataEntry ATTR=NAME:CITY CONTENT={{CITY}}
 TAG POS=1 TYPE=INPUT:TEXT FORM=NAME:WebDataEntry ATTR=NAME:ZIP CONTENT={{ZIP}}
 'Tip: Use the string ($) instead of the index to select the state and country
 'Index would be the position of an entry in the combo box list, e. g. 161 for United States
 'The $ option is more robust against changes of the combo box content
 'Note * is used to ignore leading and trailing blanks that could be in the input data
 TAG POS=1 TYPE=SELECT FORM=NAME:WebDataEntry ATTR=NAME:STATEID CONTENT=$*{{STATE-ID}}*
 TAG POS=1 TYPE=SELECT FORM=NAME:WebDataEntry ATTR=NAME:COUNTRYID CONTENT=$*{{COUNTRY-ID}}*
 TAG POS=1 TYPE=INPUT:TEXT FORM=NAME:WebDataEntry ATTR=NAME:EMAIL CONTENT={{EMAIL}}
 TAG POS=1 TYPE=INPUT:SUBMIT FORM=NAME:WebDataEntry ATTR=NAME:SendButton&&VALUE:Click<SP>to<SP>submit<SP>data 
 TAG POS=1 TYPE=A ATTR=TXT:Back
Nill2016
 
Posts: 3
Joined: Thu Feb 09, 2017 2:51 pm


Return to Command Line and Scripting Interface

Who is online

Users browsing this forum: No registered users and 3 guests

-->