VBA IE Automation

moni_tm

New Member
Joined
Nov 4, 2015
Messages
29
Good Afternoon,

I am trying to build a workbook to process invoices. I've been able to setup the code to go through our payment system login page but when I get to entering the invoice details I get the following error message(s).

"Run-time error '91': Object Variable or With block variable not set"

I believe this has something to do with the following code not being able to find the HTML element, it is there as an "ID" and "Name".

Code:
Set BU = .document.getElementById("MI_VCHRQST_ADVW_BUSINESS_UNIT")
    BU.Value = ws.Range("A" & ActRow).Value

With the above, "BU" gets set to nothing and throws out the runtime 91 error.

If I change the "getElementById" to "getElementsByName" i get a Runtime error 438. with "ElementsByName", If i remove the .Value from BU the code stores the data from excel in vba but does not transfer to the webpage.

FULL CODE :

Code:
'Option Explicit
Sub INVOICE_PROCESSOR()

'================================================================
'SETTINGS
'Application.ScreenUpdating = False
'Application.Calculation = xlCalculationManual
'Application.DisplayAlerts = False

'================================================================
'VARIABLES

Dim wb As Workbook: Set wb = ThisWorkbook
Dim ws As Worksheet: Set ws = wb.Sheets("INVOICES")
Dim IE As Object: Set IE = New InternetExplorerMedium
Dim ActRow As Integer: ActRow = ws.Range("A:A").Find("Business Unit").Offset(1, 0).Row

Dim EID As HTMLInputElement
Dim PASSWORD As HTMLInputElement

'Dim BU As HTMLInputElement
'Dim VEND_ID As HTMLInputElement
'Dim VEND_LOC As HTMLInputElement
'Dim INV_ID As HTMLInputElement
'Dim INV_DATE As HTMLInputElement
'================================================================
'CODE

'OPEN INTERNET EXPLORER AND NAVIGATE TO AP INPUT PAGE

With IE
    .Visible = True
    .navigate ws.Range("B1").Value
    
Do While .Busy
    DoEvents
Loop
Do While .readyState <> 4
    DoEvents
Loop

'LOGGING IN
On Error GoTo INV_ENTRY

Set EID = .document.getElementById("username")
    EID.Value = ws.Range("b2").Value

Set PASSWORD = .document.getElementById("password")
    PASSWORD.Value = InputBox("Enter EID Password")
'    PASSWORD.Value = ""
    .document.forms(0).submit
        
INV_ENTRY:

Do While .Busy
    DoEvents
Loop

Do While .readyState <> 4
    DoEvents
Loop
'Application.Wait (Now + TimeValue("00:00:10"))

'BEGIN INVOICE PROCESSING

'!!!!!!!!!!!!! error here

Set BU = .document.getElementById("MI_VCHRQST_ADVW_BUSINESS_UNIT")
    BU.Value = ws.Range("A" & ActRow).Value '<<<<<runtime error="" 91
     
Set BU = .document.getElementsByName("MI_VCHRQST_ADVW_BUSINESS_UNIT")
    BU.Value = ws.Range("A" & ActRow).Value '<<<<<runtime error="" 438
         
Set BU = .document.getElementsByName("MI_VCHRQST_ADVW_BUSINESS_UNIT")
    BU = ws.Range("A" & ActRow).Value '<<<<<vba stores="" data="" from="" workbook="" but="" does="" not="" populate="" the="" webpage
 
'Set VEND_ID = .document.getElementById("MI_VCHRQST_ADVW_VENDOR_ID")
'    VEND_ID.Value = ws.Range("B" & ActRow).Value
'
'Set VEND_LOC = .document.getElementById("MI_VCHRQST_ADVW_VNDR_LOC")
'    VEND_LOC.Value = ws.Range("C" & ActRow).Value
'
'Set INV_ID = .document.getElementById("MI_VCHRQST_ADVW_INVOICE_ID")
'    INV_ID.Value = ws.Range("D" & ActRow).Value
'
'Set INV_DATE = .document.getElementById("MI_VCHRQST_ADVW_INVOICE_DT")
'    INV_DATE.Value = ws.Range("E" & ActRow).Value
    
ws.Range("G" & ActRow).Value = "COMPLETED"

ActRow = ActRow + 1

'================================================================
 .Quit
 End With
'MsgBox ("COMPLETED")
'================================================================
'RESET SETTINGS
ResetSettings:
'Application.ScreenUpdating = True
'Application.Calculation = xlCalculationAutomatic
'Application.DisplayAlerts = True

End Sub

Any help would be greatly appreciated, I'm at a loss...

Thanks

Tom</vba></runtime></runtime>
 
Last edited:

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
Thanks for reply Computerman, I have have tried as you suggested and now get a "Compile error: Syntax Error"

Code:
Application.Wait (Now + TimeValue("00:00:2"))

End IE

'BEGIN INVOICE PROCESSING

Set BU = .document.getElementById("MI_VCHRQST_ADVW_BUSINESS_UNIT")
    BU.Value = ws.Range("A" & ActRow).Value

Thanks

Tom
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,327
Members
452,635
Latest member
laura12345

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top